Hi!
I have arrays of different length (length is different within each loop)
and I want to add the number of loop as the third dimension of each array. I used B(:,:,i)= B
What I get is B(:,:,1) = B @last loop (where i=4)
B(:,:,2) = 0 @second loop (where i=2)
B(:,:,3) = 0 @third loop (where i=3)
B(:,:,4) = B @last loop (where i=4)
What I want is B(:,:,1) = B @first loop (where i=1)
B(:,:,2) = B @second loop (where i=2)
until end of loop
I would highly appreciate if someone has a straighforward answer and can help, please!
for i = 1:4
%table of data different length*20 column
dim = data(data.TC_Counter3 == i,:);
%B is array of different lenghth*20
B = table2array(dim);
B(:,:,i)= B;
end

 채택된 답변

madhan ravi
madhan ravi 2020년 7월 8일

0 개 추천

Save it as a cell instead of a 3D matrix since you say they are of different lengths.

댓글 수: 3

Mahla Bakhshi
Mahla Bakhshi 2020년 7월 8일
Thanks for the answer! I tried that, but still I get the same output.
B = cell(5, 1);
for ii = 1:5
dim = data(data.TC_Counter3 == ii, :);
B{ii} = table2array(dim);
end
celldisp(B)
Mahla Bakhshi
Mahla Bakhshi 2020년 7월 9일
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 7월 8일

댓글:

2020년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by