menu and vector equal

1 回表示 (過去 30 日間)
matt noman
matt noman 2020 年 3 月 7 日
回答済み: Geoff Hayes 2020 年 3 月 7 日
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)

回答 (1 件)

Geoff Hayes
Geoff Hayes 2020 年 3 月 7 日
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.

カテゴリ

Help Center および File ExchangeParallel Computing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by