Matlab menu sum values
3 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone,
I have a values in the menu, now I would like to choose for example two of them, and sum them. But if I read values from menu, it gives me 1 - 4 not -10000,3000 and so on ...
Please help
Thank you
clc,clear,close
n=input("Počet pohybů na účtu: ")
for i=1:n
msg = ("Vyber hodnotu: ");
vyber = ["-10000" "3000" "15000" "4000" "-6000"];
choice = menu(msg,vyber);
end
0 件のコメント
回答 (2 件)
Voss
2022 年 12 月 3 日
clc
msg = "Vyber hodnotu: ";
vyber = ["-10000" "3000" "15000" "4000" "-6000"];
n = input("Počet pohybů na účtu: ");
choice = zeros(1,n); % vector of user-selections
for i = 1:n
choice(i) = menu(msg,vyber); % store the i-th selection
end
% index the selections in vyber, convert to numbers, and sum:
result = sum(str2double(vyber(choice)))
0 件のコメント
Image Analyst
2022 年 12 月 3 日
編集済み: Image Analyst
2022 年 12 月 3 日
Try this:
clc;
clear;
n=input("Počet pohybů na účtu: ")
msg = ("Vyber hodnotu: ");
vyber = ["-10000" "3000" "15000" "4000" "-6000", "Quit"];
theSum = 0;
for k = 1 : n
choice = menu(msg, vyber);
if choice == numel(vyber)
% User clicked Quit
break;
end
selectedVyber = vyber(choice);
% Sum it in.
theSum = theSum + str2double(selectedVyber);
fprintf('You selected button #%d which is %s. The sum so far is %d.\n', ...
choice, selectedVyber, theSum)
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!