필터 지우기
필터 지우기

how can i store arrays of different sizes in each for loop?

조회 수: 61 (최근 30일)
giancarlo maldonado cardenas
giancarlo maldonado cardenas 2022년 3월 17일
댓글: Voss 2022년 3월 18일
Hi guys, how can I store arrays of different sizes in each iteration of a for loop?
for example I have this code, inside the for I have a function that in each iteration returns an array of a certain size in the second iteration it returns another array of a different size and when storing it it returns an error saying that the arrays are not the same size.
how can I store these arrays of different sizes in a single array?
thanks in advance
niterations= 100;
Nusers = 120;
vec_nack= [];%to stock
vec_ack= [];%to stock
for g=1: niterations
[vec_0,vec_1]= DETECTIONALGORITHM (Nusers);
vec_nack=[vec_nack vec_0]
vec_ack=[vec_ack vec_1]
end

채택된 답변

Voss
Voss 2022년 3월 18일
The easiest way is to use a cell array:
niterations= 100;
Nusers = 120;
vec_nack = cell(1,niterations);%to stock
vec_ack = cell(1,niterations);%to stock
for g=1: niterations
[vec_nack{g},vec_ack{g}]= DETECTIONALGORITHM (Nusers);
end
Then you can access individual elements (which are arrays) in your cell arrays using curly brace {} indexing:
% the 3rd element of vec_nack, for instance:
vec_nack{3}
  댓글 수: 4
giancarlo maldonado cardenas
giancarlo maldonado cardenas 2022년 3월 18일
Thank you very much, my friend
Voss
Voss 2022년 3월 18일
You're welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by