Filter löschen
Filter löschen

Converting a numeric array into a string array with their corresponding values

1 Ansicht (letzte 30 Tage)
I am trying to convert a user inputted resistance value to its appropriate color band.
The user is told to input a value for resistance in the form of a vector.
If, for example, the user inputs [1 0 0 0], How do I output [Brown, Black, Red] as the appropriate color band sequence using conditional statements?
When converting resistance to a color band, the following should be considered:
BLACK(0) BROWN(1) RED(2) ORANGE(3) YELLOW(4) GREEN(5) BLUE(6) VIOLET(7) GREY(8) WHITE(9)
The first and second colors in the color band are determined by their associated number.
The third, final, color in the color band is determined by the following:
black(1) brown(10) red(100) orange(1000) yellow(10000) green(100000) blue (1000000)
For example, if the user enters [2 7 0 0 0]
2 corresponds with red, 7 corresponds with violet and there are three zeros so the last color is orange
[red violet orange]
With those rules in mind, how do I complete this task?

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 21 Sep. 2018
cl = {'BLACK' 'BROWN' 'RED' 'ORANGE' 'YELLOW' 'GREEN' 'BLUE' 'VIOLET' 'GREY' 'WHITE'};
%input = [2 7 0 0 0];
input=[1 0 0 0]
s = cl([input(1:2)+1, length(input)-1])

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 21 Sep. 2018
Hint:
lookup = {'PIE', 'TART', 'PUDDING', 'CAKE'};
lookup{User_value+1}

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by