How to store vectores which have different lengts? (in a loop)

조회 수: 1 (최근 30일)
IBM watson
IBM watson 2018년 12월 13일
답변: madhan ravi 2018년 12월 13일
This doesnt work because every tupple have differents lengths :
for i=2:5
ar(i,:)=ones(1,q(i)-q(i-1)+2);
end
q is a random generated vector here.
What I intended to do is:
ar(2,:)=ones(1,q(2)-q(1)+2)
ar(3,:)=ones(1,q(3)-q(2)+2)
.
.
.

채택된 답변

madhan ravi
madhan ravi 2018년 12월 13일
Store it as cell like below:
ar=cell(1,4);
for i=2:5
ar{i-1}=ones(1,q(i)-q(i-1)+2);
end
celldisp(ar)

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by