user defined variable input
2 ビュー (過去 30 日間)
古いコメントを表示
If i have sample formula k=aX1*aX2*aX3*......*aXn. here X1,X2,...Xn are vector of X=[X1 X2 ... Xn]... if user input has only 2 component X1,X2 the output will be k=aX1*aX2. if user has n component in the vector then the output will be k=aX1*aX2*aX3*......*aXn. how to solve such a case
0 件のコメント
採用された回答
ES
2018 年 3 月 5 日
Get the user input of X using input function. Then get the length of X using length function.
Run a for loop on length of X and multiply with 'a'.
2 件のコメント
Stephen23
2018 年 3 月 5 日
Note that it is recommended to avoid length, and only use numel or size. This avoids bugs caused by length measuring different dimensions without warning.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!