I want to know how to assing variable value depending on the value it self. Explained in detail below.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
akash sonnad
am 7 Jan. 2019
Kommentiert: akash sonnad
am 8 Jan. 2019
Consider I=[2,3,5];
now depending on the values of I i want to assign other variables as
r2=2, r3=3, r5=5.
If the elements in I are huge, how do I assign the index in the variable r in a simple for loop ??
1 Kommentar
Stephen23
am 7 Jan. 2019
"now depending on the values of I i want to assign other variables as r2=2, r3=3, r5=5."
That is not a good approach to writing code. Read this to know why:
It would be much simpler and more efficient to just use indexing.
Akzeptierte Antwort
Weitere Antworten (1)
Ganesan S
am 7 Jan. 2019
Dear Sir,
Why do you want to assign a variable (I) to a different variable (r)? I(i) itself is will do the work.
Try this:
for i=1:length(I)%if I is either row vector or column vector
r(i)=I(i);
end
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!