Efficiency help 2
1 回表示 (過去 30 日間)
表示 古いコメント
for q = 1:length(maxtab2)
for r = 1: length(maxtab2{q})
for s = 1: length(replacewith)
if abs (maxtab2{q}(r) - replacewith(s)) ==1
maxtab2{q}(r) = replacewith(s);
end
end
end
end
maxtab2 is a list of cells, each containing 2 colums of numbers(up to 20 numbers each column).
length(maxtab2)=190 length(maxtab2{q}) would be up to 20
can anyone help me make the 3 loops more effecient please? It is taking way too long right now, Thanks!
here is the data for maxtab2, its just the content of 1 cell
{[705;4000]}
replacewith is a list of over 5000 variables. the code here chooses one of these 5000 variable and replace the corresponding maxtab2 (determined by the for loops) with the chosen variable from replacewith
2 件のコメント
Sean de Wolski
2011 年 12 月 7 日
I agree with Sven. Why?
"Because the mathematician knew it was a good idea."
採用された回答
Sean de Wolski
2011 年 12 月 7 日
for s
if abs (maxtab2{q}(r) - replacewith(s)) ==1
maxtab2{q}(r) = replacewith(s);
end
end
I'm pretty sure this can be replaced with
maxtab{q}(r) = find(abs(maxtab{q}(r)-replacewith)==1,1,'last')
but this operation seems wierd to me. You're going to replace it with the value one less than it or one more than it, you're aware of this right?
その他の回答 (1 件)
Jerry
2011 年 12 月 7 日
If this maxtab2 can be stored in a matrix. This whole thing can be done without iteration. But if it's a cell, I think it's pretty hard to speed it up since a lot of operations cannot be applied to cell, like "-"(minus), and "find".
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!