not to use loops
古いコメントを表示
x=[2,3,4,5;1,3,2,5;8,7,6,5];
y=[-1,2,3,6;8,6,7,5;10,11,12,18];
z=[1,2,3,4;5,18,7,8;12,16,35,-8];
[yuk,idx]=max(z) %as andrei says (http://www.mathworks.com/matlabcentral/answers/17409-without-using-loops)
here z is a function of x and y and the question is to find which corresponds to the max z in each column in the matrices x and y
in short i need to find elements of matrices in each column using idx without using loops For example in the 1. colum max z is 12 and find x is 8 y is 10
3 件のコメント
Daniel Shub
2011 年 10 月 4 日
Over the past 10 years or so the JIT accelerator has substantially sped up loops in MATLAB. While there are lots of cases where vectorized code is still faster, if you can solve your problems with a loop, there may be no reason to try and do it without a loop (i.e., the improvement in performance may not be worth it).
osman
2011 年 10 月 4 日
Daniel Shub
2011 年 10 月 4 日
In some ways the loops are perfect. It means you can just borrow a bunch of computers one night and your simulation will be done. Way better than wasting your time trying to optimize code.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!