how do i write a function that can choose a desired number of statistic from a given list?

2 ビュー (過去 30 日間)
for example i have a vector with variables, and my list of statistics are min,max,mean,median and std. i need to write a function that will help me choose 3 out of the given list of statistic and represent on a script.
  3 件のコメント
Brenda Egbe
Brenda Egbe 2018 年 10 月 9 日
i need to use the elseif statement to choose any of the statistic that will be entered as an input in the command window
Image Analyst
Image Analyst 2018 年 10 月 9 日
編集済み: Image Analyst 2018 年 10 月 9 日
No you don't. If you want 3 (or any number) to be executed, you want to have 3 independent if statements with NO elseif.

サインインしてコメントする。

採用された回答

Kevin Chng
Kevin Chng 2018 年 10 月 9 日
Hi Brenda,
function choose3(a,b,c)
simplevar = [1 2 3 4 5 6];
a = string(a);
b = string(b);
c = string(c);
if ~isstring(a) || ~isstring(b) || ~isstring(c)
error('Your input is not compatible');
end
if strcmp(a,'min')==1 || strcmp(b,'min')==1 || strcmp(c,'min')==1
fprintf('the minimun is %d \n',min(simplevar));
elseif strcmp(a,'max')==1 || strcmp(b,'max')==1 || strcmp(c,'max')==1
fprintf('the maximun is %d \n',max(simplevar));
end
end
You may duplicate the elseif for other statistical value. Try type choose3('min','max','a') in cmd.

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by