필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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?

채택된 답변

Bruno Luong
Bruno Luong 2018년 9월 21일
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])

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 9월 21일
Hint:
lookup = {'PIE', 'TART', 'PUDDING', 'CAKE'};
lookup{User_value+1}

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by