我必須做一個函數,需要3個輸入,如e0
,e1
和e2
。該功能將有2個輸出x
和y
。Matlab - 生成輸入和他們的總和的組合
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
我GOOGLE了我的問題,發現combvec和allcomb應該幫助,但我找不出如何.. 請幫助任何回答或暗示將會有很大的幫助。
非常感謝。你的回答幫了我很多。現在我清楚地明白我做錯了什麼。 – 2015-03-04 10:02:03
@Frankwiene:我的榮幸! – knedlsepp 2015-03-04 10:05:12