How can i do let Matlab returns variable name when i check its value?
Mostrar comentarios más antiguos
Assumed that, i have a code as below:
x=input('x = ');
y=input('y= ');
z=input(z= ');
...and so on.
And my condition is value of any x , y or z... (that user will give into accrossding to keyboard) is must be positive. And i mean is after user give into value of variables above. How can i do to know what variable is negative. For example, I want to my program warning that: " Variable x is negative", My code that i tried. I create a vecto that called "Ktra" and use a for loop.
x=input('x= ');
y=input('y= ');
z=input('z= ');
Ktra=[x y z];
iam = 1;
for i=1:length(Ktra)
if Ktra(i)<0
disp('Gia tri nhap can lon hon 0');
tprintf('So thu tu cua so bi am la: %d \n', iam);
end
end
Thank you so much!
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 4 de Feb. de 2017
Varnames = {'x', 'y', 'z'}
Now you can display Varnames{i}
1 comentario
Le Dung
el 4 de Feb. de 2017
Categorías
Más información sobre Structures 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!