assign subscrips to vectors

조회 수: 2 (최근 30일)
dav
dav 2013년 3월 12일
I have 5 vectors yt1, yt2, yt3,yt4,yt5 of size 200*1.
I need to assign subscripts so that I can call the vector I want in side a loop.
Can you please help me with this?
Thanks

채택된 답변

Cedric
Cedric 2013년 3월 12일
편집: Cedric 2013년 3월 12일
You probably want something like
yt = [yt1, yt2, yt3, yt4, yt5] ;
and then use
yt(:,k)
in the loop, where k is the loop index. If yt's were not all the same dimension, you could use a cell array:
yt = {y1, y2, y3, y4, y5} ;
and then use
yt{k}
in the loop.
If you want to avoid copies/aggregation, just define directly the matrix the cell array instead of defining yt1 to yt5, e.g.
yt = zeros(200,5) ; % Prealloc.
yt(:,1) = ... whatever computation you used to define yt1
yt(:,2) = ... whatever computation you used to define yt2
..
or
yt{1} = ... whatever computation you used to define yt1
yt{2} = ... whatever computation you used to define yt2
  댓글 수: 2
dav
dav 2013년 3월 12일
thank you everyone!
Cedric
Cedric 2013년 3월 12일
편집: Cedric 2013년 3월 12일
You're welcome, please check the last EDITs that I made (worded a little better, eliminated typos).

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

추가 답변 (2개)

Youssef  Khmou
Youssef Khmou 2013년 3월 12일
hi, try :
N=200;
for n=1:N
yt1(n)=.............
yt2(n)=.......
.....
end
  댓글 수: 4
dav
dav 2013년 3월 12일
I mean something like the following:
For m=1:5
ym=ytm;
end
where ytm is a full vector for m=1,2..5
Youssef  Khmou
Youssef Khmou 2013년 3월 12일
alright, i dont think that is possible but you can construct a matrix that contains the vectors :
yt1=rand(200,1);
yt2=rand(200,1);
yt3=rand(200,1);
yt4=rand(200,1);
yt5=rand(200,1);
Y=[yt1';yt2';yt3';yt4';yt5'];
for m=1:5
ym=Y(m,:);
end
ok?

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


Walter Roberson
Walter Roberson 2013년 3월 12일

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by