How can I link a matrix to a menu selections.
2 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I am currently very inexperienced with Matlab and the frustration is slightly ensuing.
I have a situation where I need to link two menu options that are selected two to different 4x5 matricies.
For example I currently have distances in miles and kilometers in two 4x5 matricies.
I have started the code with;
x = menu('Where from?' , 'A' , 'B' , 'C', 'D');
y = menu('Where to?' , 'E' , 'F' , 'G' , 'H' , 'I');
to get my menu options.
I then have my two matrcies.
kilometers = [2887 7277 11628 7171 11856
5132 4432 10360 5450 12193
2624 7366 10321 8203 13201
5344 5333 8308 7394 14816];
miles = [1235 3930 6279 3892 6402
2771 2393 5740 2943 5584
1417 3977 5573 4429 7128
2886 2880 4486 4285 8001];
I am trying to link the menu so that when the promt comes up and says 'where from?' and 'A' is sleceted, then the second promt 'where to? and 'I' is selected. It will display 'The distance from 'A' to 'I' is 14816 kilometers or 8001 miles'.
Thank you for your help in advance!
Ben
2 件のコメント
Paul Kaufmann
2021 年 8 月 4 日
It's not quite obvious, why the result of picking "A" and "I" should be 14816 or 8001. The two matrices make more sense in the scenario where the last entry (i.e. 14816) belongs to the selection of "D" and "I". Or am I missing something?
The answer by Chunru seems to go in that direction as well.
Chunru
2021 年 8 月 5 日
The two matrices have rows corresponding to cities 'A'..'D', and columns corresponding to cities 'E'...'I'. That's is my guess.
採用された回答
Chunru
2021 年 8 月 4 日
kilometers = [2887 7277 11628 7171 11856
5132 4432 10360 5450 12193
2624 7366 10321 8203 13201
5344 5333 8308 7394 14816];
miles = [1235 3930 6279 3892 6402
2771 2393 5740 2943 5584
1417 3977 5573 4429 7128
2886 2880 4486 4285 8001];
x = menu('Where from?' , 'A' , 'B' , 'C', 'D');
y = menu('Where to?' , 'E' , 'F' , 'G' , 'H' , 'I');
dist_km = kilometers(x, y);
dist_miles = miles(x, y);
fprintf('Distance from %d to %d is %.0fkm or %.0fmiles\n', 'A'+x-1, 'E'+y-1, dist_km, dist_miles)
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!