Can anyone simplify this code please?
古いコメントを表示
Morning all,
I have a problem. I'm trying to take a subset of a matrix, but not a uniform distribution. The difference between points is given in the vector phi, which I've made super long to make sure I don't reach the end of it, As you can see this vector is a 6 number repeating pattern. I've made a vector, zeta, containing the rows I would like to extract from the matrix. But, it is super clunky! Is anyone able to simplify this code for me please? I'm sure it should be possible without the loop.
phi = repmat([8.70;8.70;8.70;8.70;8.70;16.59],10,1);
% Random number generator to decide which sensor to use first
sensor = randi(6,1);
col = 1;
zeta = 1;
while col + round(phi(sensor),0) < 153
col = col + round(phi(sensor),0);
zeta = [zeta; col];
sensor = sensor + 1;
end
Many thanks
5 件のコメント
jlt199
2016 年 9 月 13 日
John D'Errico
2016 年 9 月 13 日
Why? Does it take too long to run? pre-optimizing code that has no reason to be optimized is a huge waste of time.
jlt199
2016 年 9 月 13 日
jlt199
2016 年 9 月 13 日
jlt199
2016 年 9 月 14 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!