【发布时间】:2015-05-03 05:48:12
【问题描述】:
我必须创建一个接受 3 个输入的函数,例如 e0、e1 和 e2。该函数将有 2 个输出 x 和 y。
x 将是e0、e1 和e2 的组合。 y 将是一个列向量,其中包含 x 列的总和。
创建函数必须满足以下条件:
- 输入
e0、e1和e2每个都有一个数字。 - 如果用户没有为输入输入值,则默认设置为 0。
- 如果用户未输入任何输入,则应显示未输入任何输入的消息。
这是一个例子:
combination pattern of X (first 3 columns): pattern for y is the sum of x
1 1 1 3
2 1 1 4
3 1 1 5
1 2 1 4
2 2 1 5
3 2 1 6
1 3 1 5
2 3 1 6
and so on... and so on....
到目前为止,我只能在 x 和 y 分别显示时做到这一点。
function [x,y]=create(e0,e1,e2)
switch nargin
case 2
e1=0;
e2=0;
case 1
e2=0;
case 0
disp('no input')
end
我用谷歌搜索了我的问题,发现 combvec 和 allcomb 应该有帮助,但我不知道如何.. 请帮助任何答案或提示将是一个很大的帮助。
【问题讨论】:
标签: matlab matrix combinations combinatorics cartesian-product