save result of a loop in 3D matrix
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
per isakson
2016 年 7 月 26 日
編集済み: per isakson
2016 年 7 月 26 日
"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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!