Putting Output values into a matrix.
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Edward Steen
am 24 Feb. 2017
Kommentiert: Star Strider
am 27 Nov. 2020
Hi, I have an if statement within a double for loop. I would like to be able to put the two index values that satisfy the if statement into a matrix that I can then manipulate etc. Currently, I am just using "disp" to display the two index values. How can I go about putting the values into a matrix?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 24 Feb. 2017
Bearbeitet: Star Strider
am 24 Feb. 2017
One approach:
vals = [];
for k1 = 1:10
for k2 = 1:10
if k1 == k2 % Test Condition
vals = [vals; k1 k2]; % Store Index Values
end
end
end
Here, the ‘vals’ matrix will be:
vals =
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices 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!