How do I create a matrix from from the answers of each iteration of a for loop?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Syed Azib Anaqy Al-Sahab bin Wan Madhi
am 17 Dez. 2020
Bearbeitet: Syed Azib Anaqy Al-Sahab bin Wan Madhi
am 18 Dez. 2020
This is my for loop code,
N = 4
for yn = cos(pi*(0:N)/N)
yp = cos(pi*(0:N)/N);
bottom = 1./(yn - yp)
end
This is the output,
bottom =
Inf 3.4142 1.0000 0.5858 0.5000
bottom =
-3.4142 Inf 1.4142 0.7071 0.5858
bottom =
-1.0000 -1.4142 Inf 1.4142 1.0000
bottom =
-0.5858 -0.7071 -1.4142 Inf 3.4142
bottom =
-0.5000 -0.5858 -1.0000 -3.4142 Inf
How do I create a
[Inf 3.4142 1.0000 0.5858 0.5000
-3.4142 Inf 1.4142 0.7071 0.5858
-1.0000 -1.4142 Inf 1.4142 1.0000
-0.5858 -0.7071 -1.4142 Inf 3.4142
-0.5000 -0.5858 -1.0000 -3.4142 Inf] matrix from my output, because the last bottom iteration is the final answer?
0 Kommentare
Akzeptierte Antwort
madhan ravi
am 17 Dez. 2020
N = 4;
yn = cos(pi * ( 0 : N ) / N);
yp = cos(pi * ( 0 : N ) / N);
yp = reshape(yp, 1, 1, []);
bottom = squeeze(1 ./ (yn - yp))
1 Kommentar
Syed Azib Anaqy Al-Sahab bin Wan Madhi
am 18 Dez. 2020
Bearbeitet: Syed Azib Anaqy Al-Sahab bin Wan Madhi
am 18 Dez. 2020
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!