Creating array based on highest values using for loop

2 ビュー (過去 30 日間)
Jesper Madsen
Jesper Madsen 2022 年 12 月 6 日
コメント済み: Jesper Madsen 2022 年 12 月 6 日
Hi all,
I am still new to using loops in MatLab, so hope you will bear with me.
I have a 16:1 looping vector (Peaks) consisting of the positions of the highest values obtained from each column in my 16 column data array (Reshaped_array).
I wish to use a for loop to create a new array where each column starts with the corresponding position from the looping vector, and contains the following 999 entries, so each column will contain 1000 entries, where column 1 starts with the first entry in Peaks, column 2 the second and so on. I have been using the following code:
for i=(Peaks)
x=Reshaped_array(i:999+i,:);
end
The code seems to loop through the data correctly, but rather than applying each value in Peaks once to each column in Reshaped_array, all values in Peaks seems to be applied to each column at once, leaving only the values obtained from the final loop.
I hope you can help.
Cheers,
Jesper

採用された回答

David Hill
David Hill 2022 年 12 月 6 日
x=zeros(1000,16);
c=1;
for i=Peaks
x(:,c)=Reshaped_array(i:999+i,c);
c=c+1;
end
  1 件のコメント
Jesper Madsen
Jesper Madsen 2022 年 12 月 6 日
Thak you very much for the quick response, this worked very well.
Cheers,
Jesper

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by