MATLAB Answers

menu and vector equal

1 view (last 30 days)
matt noman
matt noman on 7 Mar 2020
Answered: Geoff Hayes on 7 Mar 2020
In matlab I want to make a menu with this string array
material=["Rubber","Wood (along grain)" ,"Aluminum," "Titanium","Graphene","Steel","Cobalt-Chrome"]
if I exit out of menu I want to keep asking until a selection is made and when I select an object on the menu I want to output from the following vector
elasticity=[100000000,,11000000000.0000,69000000000.0000,110300000000.000,1050000000000.00, 200000000000.000 ,240000000000.000]
there are seven materials and seven numbers so if I select Rubber I want to output 100000000 and if I select Aluminum I want to get 110300000000.000
each material matches the number on the following vector
here is my code so
far
material=["Rubber","Wood (along grain)" ,"Aluminum," "Titanium","Graphene","Steel","Cobalt-Chrome"]
elasticity=[100000000,,11000000000.0000,69000000000.0000,110300000000.000,1050000000000.00, 200000000000.000 ,240000000000.000]
menu('Material',Mayerial(:,1)

  0 Comments

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 7 Mar 2020
matt - you don't mention what is wrong with your code or if you have tried to fix the obvious bugs with it. Do you really mean to use square brackets for the array of strings material? Do you really mean to have an empty value between the first and second element of the elasticity array? What is Mayerial in your call to menu (which is missing a closing bracket)? If you modify your code slightly to
material = {'Rubber','Wood (along grain)' ,'Aluminum', 'Titanium','Graphene','Steel','Cobalt-Chrome'};
elasticity = [100000000,11000000000.0000,69000000000.0000,110300000000.000,1050000000000.00, 200000000000.000 ,240000000000.000];
index = menu('Material',material);
if (index > 0)
fprintf('material %s has elasticity %d\n', material{index}, elasticity(index));
end
then you might get what you are looking for. If the index is zero, then you can continue (using a while loop perhaps) to query the user for a material.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags