problem with while and if loops.
Show older comments
Im having an issue where when the user inputs 'no' as the user_status variable i get an error that the arrays are no longer compatible. If I solely stick to userstatus being yes everything works perfect. The only code in question is up to the end of the if statement as the function has nothing to do with the error I believe. How can I get this error to go away?
user_status = input('would you like to find your resistor value? enter yes or no with an apostrophe on each side of the text');
while user_status=='yes'
[resistance,tolerance] = resistor_value();
user_status = input('would you like to find another resistor value? enter yes or no');
end
if user_status=='no'
user_status = input('if you would like to try again type yes');
end
%% function not important as it deals with something irrelevant
function [resistance,tolerance] = resistor_value()
first_band = {'black','brown','red','orange','yellow','green','blue','violet','grey','white'};
second_band = {'black','brown','red','orange','yellow','green','blue','violet','grey','white'};
multiplier_band = {'black','brown','red','orange','yellow','green','blue','violet','grey','white','gold','silver'};
tolerance_band = {'brown','red','orange','yellow','green','blue','violet','grey','gold','silver'};
disp(first_band)
disp('type the index in the string above of the color that correlates to your resistor starting with 0 as black, 1 as brown, and so forth')
band1num = input('your index number for band 1 is');
disp(second_band)
disp('type the index in the string above of the color that correlates to your resistor starting with 0 as black, 1 as brown, and so forth')
band2num = input('your index number for band 2 is');
disp(multiplier_band)
disp('type the index in the string above of the color that correlates to your resistor starting with 0 as black, 1 as brown, and so forth')
band3num1 = input('your index number for the multiplier band is');
band3num2 = 10^band3num1;
disp(tolerance_band)
disp('type the index in the string above of the color that correlates to your resistor starting with 0 as brown, 1 as red, and so forth')
band4num = input('your index number for the tolerance band 4 is ');
band4str = {'1%','2%','.05%','.02%','.5%','.25%','.1%','.01%','5%','10%'};
band4value = band4str{band4num};
resistance = ((band1num*10)+band2num)*band3num2;
disp('resistance is')
disp(resistance)
tolerance = band4value;
disp('tolerance is')
disp(tolerance)
end
Accepted Answer
More Answers (0)
Categories
Find more on Resampling Techniques in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!