storing output of for loop

2 ビュー (過去 30 日間)
Andrea Bae
Andrea Bae 2019 年 7 月 26 日
コメント済み: Andrea Bae 2019 年 7 月 26 日
Sorry for the redundant question in advance, but I'm really stuck as a beginner.
Trying to reorganize my data RLF1 in 1000s as different columns of a matrix. My current for loop is supposed to break the data in sequential 1000 chunks for a total of 300 columns, but I'm having trouble storing the output into my matrix. Only saves the last output (RLF1(200001:300000)) over and over again.
i = 1:1000:length(RLF1(1:300000));
store = zeros(1000,length(i));
for n = 1 : 300;
for i = 1:1000:length(RLF1(1:300000));
store(:,n) = RLF1(i:i+999);
end
end

採用された回答

David K.
David K. 2019 年 7 月 26 日
I believe your goal can be more easily solved using the built in Matlab function reshape. It looks to me like you have a 1x300000 vector that you would like to turn into a 1000x300 array. reshape function can do that like this :
store = reshape(RLF,[1000,300]);
If you wish to be sure that this is working the way you want it to, you can test it by making RLF 1:300000 first.
If instead, you want to continue doing it with a loop the following code should work fine
store = zeros(1000,300);
for n = 1:300
store(:,n)=RLF(1+(n-1)*1000 : n*1000);
end
The indexing there causes the indexes to go from 1:1000, 1001:2000, 2001:3000 and so on.
Hope this helps
  1 件のコメント
Andrea Bae
Andrea Bae 2019 年 7 月 26 日
This works perfectly!! Thank you so much!!!!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by