Task: Write a complete MATLAB program that meets these specifications: Prompts t
ID: 2268500 • Letter: T
Question
Task: Write a complete MATLAB program that meets these specifications: Prompts the user to enter a string. The letters in the string represent the colors of each band. Calculates the correct numeric resistance (in ohms) that corresponds to the color bands. Notes: You may ignore the 4th band. Use these single letters for the colors: Black, brown, red, orange, yellow, green, blue, violet, Grey, white, gold, silver Try to make your code modular If you have a script, put a comment block at the top with course, section, date, and your name. Document your code with appropriate comments. Upload your MATLAB code (named resistor. m) to the HW-al D2L Submission Folder Sample Output 0: [B]lack, 1:[b]rown, 2: [rled 3: [o]range, 4: [ylellow 5:[green, 6:bl(u]e, 7:[y]iolet, 8:[6]rey, 9:[w]hite A-1:gol[d],A-2: [s]ilver Enter resistor color string: bBd The resistance value is 1 ohm Enter resistor color string: rrt The resistance value is 220 ohms Enter resistor color string: bBr The resistance value is 1000 ohms Enter resistor color string: yvo The resistance value is 47000 ohms Enter resistor color string: gug The resistance value is 5.6e+06 ohms Enter resistor color string: Gry The resistance value is 820000 ohms 6Explanation / Answer
MATLAB CODE
%% VARIABLES ARE GIVEN VALUES
B=0;
b=1;
r=2;
o=3;
y=4;
g=5;
u=6;
v=7;
G=8;
w=9;
d=-1;
s=-2;
prompt = 'Enter resistor color string ';
str = input(prompt,'s'); %% accepts string value
%% conditional statements for comparision
for i=1:3
if isequal(str(i),'B')
band(i)=B;
elseif isequal(str(i),'b')
band(i)=b;
elseif isequal(str(i),'r')
band(i)=r;
elseif isequal(str(i),'o')
band(i)=o;
elseif isequal(str(i),'y')
band(i)=y;
elseif isequal(str(i),'g')
band(i)=g;
elseif isequal(str(i),'u')
band(i)=u;
elseif isequal(str(i),'v')
band(i)=v
elseif isequal(str(i),'G')
band(i)=G;
elseif isequal(str(i),'w')
band(i)=w;
elseif isequal(str(i),'d')
band(i)=d;
elseif isequal(str(i),'s')
band(i)=s;
end
end
resistance=(band(1)*10+band(2))*10^(band(3));
%% fprintf for printing output
fprintf('The resistnace value is %d Ohms',resistance);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.