Working with a three dimensional matrix
古いコメントを表示
I have a matrix with three dimensions, and I need to take two dimensions through the use of cycle FOR.
For example:
Name variable Value
k <39x17x60>
And I need this:
a = 60;
for i = 1:60;
l = k...; %size of l <39x17>
xlswrite...;
end
採用された回答
その他の回答 (1 件)
Kenneth Eaton
2011 年 1 月 24 日
If you're asking how you would index k in your loop to get a 2-D submatrix, you would do the following:
l = k(:,:,i);
14 件のコメント
Paulo Silva
2011 年 1 月 24 日
I wasn't fast enough, you posted first :)
% k <39x17x60>
k=randn(39,17,60); %example data
%And I need this:
l=zeros(39,17); %preallocation of l
for i = 1:60
l=k(:,:,i); %size of l <39x17>
%xlswrite...;
end
Pepa
2011 年 1 月 25 日
Paulo Silva
2011 年 1 月 25 日
please explain exactly what doesn't work in your simple code?
Pepa
2011 年 1 月 25 日
Kenneth Eaton
2011 年 1 月 25 日
Pepa, I'm still not clear on exactly what error/problem you are having when you run your code. The two screenshots of the variables look fine. Note that kunn(:,:,1) and jaj are the same, there is just a scaling factor of 1.0e+003 used to display kunn.
Pepa
2011 年 1 月 25 日
Walter Roberson
2011 年 1 月 25 日
By the way, preallocation of jaj is not needed as you are overwritten its complete contents each trip through the loop.
Walter Roberson
2011 年 1 月 25 日
Pepa, put in kunn(:,:,X) *where* ?? Code example, please.
Pepa
2011 年 1 月 25 日
Oleg Komarov
2011 年 1 月 25 日
Why don't you apply what Kenneth suggested (not to mention Walter):
jaj = kunn(:,:,s)
And what's the problem, btw, can you elaborate, post any error message or unwanted result?
Pepa
2011 年 1 月 25 日
Pepa
2011 年 1 月 25 日
Oleg Komarov
2011 年 1 月 25 日
isequal(kunn(:,:,1),kunn(:,:,2)) should be 0, can you confirm?
Pepa
2011 年 1 月 25 日
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!