How can I link a matrix to a menu selections.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ben Hischar
el 4 de Ag. de 2021
Comentada: Chunru
el 5 de Ag. de 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');
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 comentarios
Paul Kaufmann
el 4 de Ag. de 2021
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
el 5 de Ag. de 2021
The two matrices have rows corresponding to cities 'A'..'D', and columns corresponding to cities 'E'...'I'. That's is my guess.
Respuesta aceptada
Chunru
el 4 de Ag. de 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)
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!