vectorization
古いコメントを表示
Can someone give me a push in the right direction regarding vectorising a loop. Is it possible to vectorise any loop? If so, I have the following script:
Names = fieldnames(Data);
for i = 1:length(fieldnames(Data));
for j = 1:length(Data.(Names{i}));
index = (Data.(Names{i}){j,1}(:, 1)==211);
Data.(Names{i}){j,1} = Data.(Names{i}){j,1}(index, :);%
end
end
Where 'Data' is a (1x3) structure. Although this particular loop doesn't take long to run, it seems like a good place to start to learn how to vectorise instead of using loops.
Any advice would be much appreciated.
3 件のコメント
Walter Roberson
2012 年 1 月 17 日
There are loops which cannot be vectorized. (I have not examined your code to see if yours is one of them.)
Sean de Wolski
2012 年 1 月 17 日
I think you should describ ehow data is organized and how it's indexed. I think you might be able to simplify that which would in turn make vectorization easier.
Richard
2012 年 1 月 18 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!