フィルターのクリア

How to create multiple matrix using for loop?

3 ビュー (過去 30 日間)
Kirti
Kirti 2012 年 11 月 26 日
Hi all, I am having y=[1 2 3 4 5 6 7 8 9 10] as data. i want to write array x1 =[ 1 2 3 4 5] x2 =[2 3 4 5 6] x3= [3 4 5 6 7] like this upto x6 =[6 7 8 9 10]. please help me to create this using matlab. I tried as follows :n=10;k=6;m=5; for i=1:k for j=i:i+m-2 x[i]= a(j); end end but it is not working!!

採用された回答

Ilham Hardy
Ilham Hardy 2012 年 11 月 26 日
ya = [1,2,3,4,5,6,7,8,9,10];
for iy = 1:(length(ya)/2)+1
xa(iy,:) = ya(iy:4+iy);
end

その他の回答 (3 件)

Amin Bashi
Amin Bashi 2012 年 11 月 26 日
y=[1 2 3 4 5 6 7 8 9 10]
x = y([1:5;2:6;3:7;4:8;5:9;6:10])

Muruganandham Subramanian
Muruganandham Subramanian 2012 年 11 月 26 日
Hi..
try this code
a=[1:10];
for i=1:numel(a)
if i==a(1)
disp(a)
elseif i<=6
a(1)=[];
disp(a)
else
break;
end
end

Kirti
Kirti 2012 年 11 月 26 日
Thanks liham Hardy
  1 件のコメント
Kirti
Kirti 2012 年 11 月 27 日
when i use same logic for long data i got subscripted assignment diamentiopn mismatch error.eg. i wrote the code as t=-pi :0.01244:pi y=sin(t) n=length(y); m=n/2;k=n+1-m; for iy=1:k; xa(iy,:)=y(iy+m-1); end disp(xa). I want a sine wave of 504 samples ,add it with White guassian noise.then write sampled sine wave in terms of lagged vectors and then finally the trajectory matrix.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by