Looping through a 3D matrix

27 ビュー (過去 30 日間)
Robert
Robert 2015 年 11 月 4 日
コメント済み: TastyPastry 2015 年 11 月 5 日
I have a 3D matrix 35,43,144
I want to run the following code such that it performs the function element by element through the 3rd dimension (using 144 data points) I want this to be done for every pixel giving me 1505 outputs (35x43)
I just can't seem to figure out the correct loop inputs
p = load ('JPLCSRmean.mat')
GRACE = p.datamean
ncol = size(GRACE,2);
for k = 1:144
j = 1:43
i = 1:35
[c,l] = wavedec(GRACE(i,j,k),4,'dmey');
al = appcoef(c,l,'dmey',1);
%[cD1,cD2,cD3,cD4,cD5,cD6] = detcoef(c,l,[1,2,3,4,5,6]);
D = [];
%D(:,6)= wrcoef('a',c,l,'dmey',6);
%D(:,5) = wrcoef('a',c,l,'dmey',5);
D(:,4) = wrcoef('a',c,l,'dmey',4);
D(:,3) = wrcoef('a',c,l,'dmey',3);
D(:,2) = wrcoef('a',c,l,'dmey',2);
D(:,1) = wrcoef('a',c,l,'dmey',1);
filename = sprintf('%s_%04f.txt', 'GRACE_APROXIMATIONS', k)
csvwrite(filename,D)
end

回答 (1 件)

TastyPastry
TastyPastry 2015 年 11 月 4 日
for i = 1:144
for j = 1:43
for k = 1:35
myVal = myData(i,j,k);
%do something
end
end
end
  2 件のコメント
Robert
Robert 2015 年 11 月 4 日
編集済み: Robert 2015 年 11 月 4 日
Thanks, so now my code looks like this
p = load ('JPLCSRmean.mat')
GRACE = p.datamean
ncol = size(GRACE,2);
for i = 1:144
for j = 1:43
for k = 1:35
[c,l] = wavedec(GRACE(i,j,k),4,'dmey');
al = appcoef(c,l,'dmey',1);
%[cD1,cD2,cD3,cD4,cD5,cD6] = detcoef(c,l,[1,2,3,4,5,6]);
D = [];
%D(:,6)= wrcoef('a',c,l,'dmey',6);
%D(:,5) = wrcoef('a',c,l,'dmey',5);
D(:,4) = wrcoef('a',c,l,'dmey',4);
D(:,3) = wrcoef('a',c,l,'dmey',3);
D(:,2) = wrcoef('a',c,l,'dmey',2);
D(:,1) = wrcoef('a',c,l,'dmey',1);
filename = sprintf('%s_%04f.txt', 'GRACE_APROXIMATIONS', k)
csvwrite(filename,D)
end
end
end
I think it is running allright but the outputs aren't saving properly, I think it is to do with where I have 'k' in this line
filename = sprintf('%s_%04f.txt', 'GRACE_APROXIMATIONS', k)
What can I replace k with to give me 1505 outputs of 35x43?
At the moment I am just getting 35 outputs that keep saving over eachother
TastyPastry
TastyPastry 2015 年 11 月 5 日
You could declare a tracking variable outside the entire loop and increment it each time you print a file.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by