changing the existing variables on the for loop
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kerem Yüksel
am 20 Aug. 2021
Bearbeitet: Stephen23
am 23 Aug. 2021
I want to change the r value to k value and vice versa for k value at the end of each loop. for example according to the following example, r and k are 4 6 8 10 at the end of first loop but i want k as 6 8 10 12. so after that for the second loop r will add up with 5 and k will add up with 3 and again the variables will change. how can i do this implementation?
abc=[1 3 5 7]
for t=1:3
k=abc+3
r=5+abc
r=k
k=r
end
k = 4 6 8 10
r = 6 8 10 12
r = 4 6 8 10
k = 4 6 8 10
k = 4 6 8 10
r = 6 8 10 12
r = 4 6 8 10
k = 4 6 8 10
k = 4 6 8 10
r = 6 8 10 12
r = 4 6 8 10
k = 4 6 8 10
4 Kommentare
Akzeptierte Antwort
Stephen23
am 20 Aug. 2021
abc = [1,3,5,7];
k = abc;
r = abc;
for ii = 1:5
[r,k] = deal(k+3,r+5)
end
6 Kommentare
Weitere Antworten (0)
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!