How to check in one loop for multiple values V1,V2,V3... I have write the code but I am not getting value multiplied in answer
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Fransi Mittal
am 15 Jan. 2022
Kommentiert: Fransi Mittal
am 15 Jan. 2022
V1= char(937);
V2=['k' char(937)];
R(1)=2;
R(2)=3;
n=2;
for i=1:n
V=['V',num2str(i)];
switch V
case char(937)
R(i)=R(i)*1;
case ['k' char(937)]
R(i)=R(i)*1000;
end
end
disp(R(1));
disp(R(2));
How to check in one loop for multiple values V1,V2,V3... I have write the code but I am not getting value multiplied in answer
2 Kommentare
Akzeptierte Antwort
Simon Chan
am 15 Jan. 2022
One possible way is to use a cell array instead of different variables as following:
Use only one variable V.
V(1) = {char(937)};
V(2) ={['k' char(937)]};
R(1)=2;
R(2)=3;
n=2;
for i=1:n
switch V{i}
case char(937)
R(i)=R(i)*1;
case ['k' char(937)]
R(i)=R(i)*1000;
end
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!