3 views (last 30 days)
Ben Hischar on 4 Aug 2021
Commented: Chunru on 5 Aug 2021
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');
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'.
Ben
##### 2 CommentsShowHide 1 older comment
Chunru on 5 Aug 2021
The two matrices have rows corresponding to cities 'A'..'D', and columns corresponding to cities 'E'...'I'. That's is my guess.

Chunru on 4 Aug 2021
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)

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!