For Loop in 3D Array
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MarshallSc
am 31 Mai 2022
Kommentiert: MarshallSc
am 31 Mai 2022
For 2D arrays, the operation that I want to execute is:
a = rand(3,3);
for i = 1:numel(a)
for j = 1:numel(a)
out(i,j) = (a(i) - a(j)) / (a(i) + a(j));
end
end
Which will turn the out into a skew-symmetric matrix. Now I want to perform the same operation instead the matrix is in 3D, how can I do that? The speed is important since my original matrix is (100,100,726). Thanks!
0 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 31 Mai 2022
Bearbeitet: Dyuman Joshi
am 31 Mai 2022
a = rand(3,3,4);
for k=1:size(a,3)
y=a(:,:,k);
for i=1:size(y,1)
for j=1:size(y,2)
out(i,j,k)=(y(i) - y(j))/(y(i) + y(j));
end
end
end
out
2 Kommentare
Dyuman Joshi
am 31 Mai 2022
It will be skew-symmetric matrix. I have made an edit, take a look at it again.
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!