How to loop over a series of files
조회 수: 2 (최근 30일)
이전 댓글 표시
I have 10 datasets named data1, data2,data3,...,data10 with dimensions [150,120, 25, 5]. I want to create a big matrix and put all this data in.
The new matrix should have dimensions [150,120,25, 5, 10]. I tried to make a for loop but I got it wrong. Below is my code
Big_matrix = zeros(150,120,25,10);
for i=1:10
Big_matrix(:,:,:,:,i)=data(i);
end
Can anyone please help with that?
댓글 수: 5
Rik
2019년 3월 15일
Have you read the documentation for the cat function? The first input is the dimension in which your arrays (the later inputs) should be concatenated. So to concatenate in the 5th dimension, use cat(5,D{:}) instead.
답변 (1개)
Rik
2019년 3월 14일
You should avoid eval. Make sure to never need it by having a better data structure.
Big_matrix=eval(['cat(4' sprintf(',data%d',1:5) ')']);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!