Please help to vectorize this for loop

Dear all,
I would like some help in vectorizing this for loop:
k=1; for i=6:5:121;
R(:,k)= rawdata{1,i};
MF(:,k)= rawdata{1,i+1};
QF(:,k)=rawdata{1,i+2};
SF(:,k)=rawdata{1,i+3};
k = 1+k;
end
The rawdata is in the form of cell arrays within cell arrays, I have attached a screenshot of how it looks. The end results for R, MF, QF and SF is a table with what is extracted from the rawdata. I want to find a way to remove this for loop and I read that vectorization is a way of optimize for loops.
Thank You,
M

 採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 9 月 2 日
編集済み: Andrei Bobrov 2017 年 9 月 3 日

0 投票

d = rawdata(6:end);
d = reshape(d,5,[])';
out = d(:,1:4);
% R = out(:,1); MF = out(:,2); and etc.
or just
out = rawdata(bsxfun(@plus,6:9,(0:5:numel(rawdata)-6)');
% R = out(:,1); MF = out(:,2); and etc.

1 件のコメント

Mariam Salem
Mariam Salem 2017 年 9 月 3 日
Thank You ^^ This is very helpful

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および 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