Menu command list of colors converted to integers

조회 수: 2(최근 30일)
Jacob Belouin
Jacob Belouin 2021년 10월 15일
댓글: Jacob Belouin 2021년 10월 15일
Hi everyone,
Taking a Matlab class this semester and I was looking for a jumping off point for my assignment. I have to use a menu command (has to be menu even though matlab says its no longer recomended) to list off 10 color options. The colors have a number value that is also 1:10, but I dont know how to assign the user selected color to the number value. The program is supposed to calculate the value and range of a resistor, but I can't get to the function portion without being able to assign values to the user selection.
Thanks

답변(1개)

DGM
DGM 2021년 10월 15일
I know this is part of the other question, but to clarify, the menu() command simply returns the index of the selected element within the list of choices. In other words, there really isn't a need to explicitly define the relationship between the color list and the values 1:10; those values are already the indices within the color list itself.
colornames = {'john deere yellow','international yellow','new holland yellow'};
% this will return a scalar integer from 1 to 3
idx = menu('yeah i know you said yellow, but which one?',colornames)
  댓글 수: 1
Jacob Belouin
Jacob Belouin 2021년 10월 15일
Man I made this post so i would have to bother you again lol

댓글을 달려면 로그인하십시오.

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by