save result of a loop in 3D matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mori
am 26 Jul. 2016
Bearbeitet: per isakson
am 26 Jul. 2016
I have this code but I want my result, distance(ii,jj), saved as a page in 3D matrix. Now just it is just overwrite on top each other
df =
1.0e+11 *
0.3852 0.3605 0.5540 0.6668 0.5226 0.6025 0.8195 0.8423 0.9269
0.2410 0.4679 0.7597 0.9946 1.0727 0.9760 0.9604 1.0346 0.8623
0.5694 0.6564 0.7458 0.7425 0.8771 1.0497 1.2131 1.1388 1.2154
0.8555 0.7848 1.0739 1.1391 1.1230 0.9836 0.7966 0.7095 0.6531
0.6998 0.6431 0.6936 0.7885 0.8024 0.9284 0.8764 0.8015 0.9041
0.5195 0.5085 0.4162 0.5908 0.5084 0.6002 0.6225 0.4920 0.7530
0.2877 0.3947 0.4268 0.3759 0.3601 0.3251 0.4967 0.4093 0.5233
0.2765 0.2424 0.2900 0.3218 0.2691 0.3227 0.3089 0.4034 0.6028
0.3165 0.2372 0.2403 0.3236 0.5012 0.5543 0.5202 0.6918 0.4386
0.3804 0.2358 0.2997 0.3831 0.4862 0.6534 0.8662 0.8330 0.5895
 
w=9;
l=10;
Distant=zeros(w,l,w*l);
for nn=1:w;
for mm=1:l;
Id = [nn mm], LOAD=df(nn,mm)
for ii=1:w;
for jj=1:l;
distance(ii,jj)=sqrt((ii-Id(1,1))^2+(jj-Id(1,2))^2);
for kk=1:w*l;
Dis(:,:,kk)=distance;
end
end
end
end
end
0 Kommentare
Akzeptierte Antwort
per isakson
am 26 Jul. 2016
Bearbeitet: per isakson
am 26 Jul. 2016
"saved as a page in 3D matrix"   Does the order of the "pages" matter? Try
>> D = cssm( df );
>> whos D
Name Size Bytes Class Attributes
D 9x10x90 64800 double
>> any(isnan( D(:)))
ans =
0
where
function D = cssm( df )
W = 9;
L = 10;
D = nan(W,L,W*L);
for nn=1:W;
for mm=1:L;
Id = [nn,mm];
% LOAD = df(nn,mm);
distance = nan(W,L);
for ii=1:W;
for jj=1:L;
distance(ii,jj)=sqrt((ii-Id(1,1))^2+(jj-Id(1,2))^2);
end
end
n3 = (nn-1)*L + mm;
D(:,:,n3) = distance;
end
end
end
Note that LOAD and thus df are not used.
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!