REPEATING COMMAND BY FUNCTION
Mostrar comentarios más antiguos
A small code has been created to check the a sensor's input variable value as per its scaling values. The code runs like this:
clear all;
clc;
sval=0;
p1='Please enter Minimum Range of Sensor Input : ';
smin=input(p1);
p2='Please enter Maximum Range of Sensor Input : ';
smax=input(p2);
p3='Please enter Minimum Range of Sensor Output : ';
inmin=input(p3);
p4='Please enter Maximum Range of Sensor Output : ';
inmax=input(p4);
rate=(smax-smin)/(inmax-inmin);
offset=smin-(inmin*rate);
show=['Your Scaling Rate will be : ',num2str(rate)];
disp(show)
show1=['Your Offset will be : ',num2str(offset)];
disp(show1)
p5='Do you want to calculate now [Y/N] : ';
str=input(p5,'s');
if str=='y' || str=='Y'
p6='Please enter output value of sensor : ';
inpt=input(p6);
if inpt<inmin || inpt>inmax
sprintf('Input value out of range')
else
sval=(inpt*rate)+offset;
show2=['Value input at sensor is : ',num2str(sval)];
disp(show2)
end
end
Now, after displaying the present values, we need to go back to the part where we ask the user whether they want to calculate now. In C++, we generally used the "GOTO" command for this. But we guess it is not available in Matlab. Also, when we tried to create a function, an error is shown as:
function recap
p5='Do you want to calculate now [Y/N] : ';
str=input(p5,'s');
"FUNCTION keyword use is invalid here. This might cause later messages about END. "
Please suggest some solution!!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!