for i=2:10
a=...
end
I want to store matrixes as an element of a set for every cycle. I know they can be stored in a vector but in my main code loop may returns different number of elements over time.
example:
a=[2], a=[29 3], a=[3 2]
and set should be:
cluster={2, 29 3, 3 2}

댓글 수: 2

Is this what you want?
a=[2], a=[29 3], a=[3 2]
and set should be:
cluster={2, 29 3, 3 2}
a is your variable, then store to cluster?
IBM watson
IBM watson 2018년 10월 22일
편집: IBM watson 2018년 10월 22일
Yes my loop is returning many vectors with different lengths. I want to store all vectors. And in the end of the code i should tell how many vectors i have stored. a=[1] , a=[2 5], a=[1 4 5]
all of these count as 1.

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

 채택된 답변

Kevin Chng
Kevin Chng 2018년 10월 22일

2 개 추천

a1=[2]; a2=[29 3]; a3=[3 2];
I will change them to cell array first for indexing, it is always my preference.
a(1)=num2cell(a1);
a(2)=num2cell(a2);
a(3)=num2cell(a3);
How to know the number of variable?
numVar = length(a); %or
numVar = numel(a); %or
numVar = size(a,2);
display your variable
a{:}

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 10월 22일
편집: KALYAN ACHARJYA 2018년 10월 22일

0 개 추천

a1=[2]; a2=[29 3]; a3=[3 2];
cluster=[a1,a2,a3];
Command Window
cluster
cluster =
2 29 3 3 2
Note: In your question, if you represents the all vectors with same name then Matlab store the last last value only
a=[2], a=[29 3], a=[3 2]
a =
2
a =
29 3
a =
3 2

댓글 수: 1

IBM watson
IBM watson 2018년 10월 22일
But can i calculate how many vectors did i stored on this code ?

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2018년 10월 22일

답변:

2018년 10월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by