Need Help Forming a Matrix from an Array

so i have an array that is (4051x1), called xvoltage, and I need to form a matrix with this vector only, I want to do something like a sliding window, that the first row are samples 2650:2655, and then the second row world be from 2651:2656 , and so on successively, can someone help me out i'm stuck , it just keeps repeating the same values forming a five by five matrix.
for p=1:5
for q=1:5
xV(p,q)=xvoltage(2650+q);
end
end

 採用された回答

Stephen23
Stephen23 2018 年 8 月 10 日
編集済み: Stephen23 2018 年 8 月 10 日

1 投票

You could use hankel. Where A is your 4051x1 array:
hankel(A(2650:end-4),A(end-4:end))

3 件のコメント

Marvin Castellanos
Marvin Castellanos 2018 年 8 月 10 日
thanks! I just modified it a little bit, to get a specific amount of data 5X5 matrix and then a 200 X 200 , this helped me alot, would it have been hard doing this with a for cycle?
Stephen23
Stephen23 2018 年 8 月 10 日
編集済み: Stephen23 2018 年 8 月 10 日
" would it have been hard doing this with a for cycle?"
Something like this perhaps (untested):
V = [rows that you want to get];
C = 5; % number of columns
N = numel(V);
M = nan(N,C);
for k = 1:N
M(k,:) = A(V(k)+(0:C-1));
end
Marvin Castellanos
Marvin Castellanos 2018 年 8 月 10 日
thanks ,i just tested it, and subtracted both matrices from different methods to double check they were the same and boom, they were , thanks a bunch!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by