I have this code :
for alfa1=0.005:.00005:0.03
(.....)
p=round(max(size(z))/4);
soln1=z(:,1);
soln1=soln1(end-p:end);
soln2=z(:,2);
soln2=soln2(end-p:end);
soln3=z(:,3);
soln3=soln3(end-p:end);
soln4=z(:,4);
soln4=soln4(end-p:end);
s1(dim)=max(soln1);
s2(dim)=min(soln1);
i1(dim)=max(soln2);
i2(dim)=min(soln2);
p1(dim)=max(soln3);
p2(dim)=min(soln3);
q1(dim)=max(soln4);
q2(dim)=min(soln4);
A(dim)=alfa1;
dim=dim+1;
count=count+1;
end
So i have this code , and it literally takes minutes to run , i wonder if someone can help me , i dont know how to preallocate the variables , in order to improve speed.

1 件のコメント

Stephen23
Stephen23 2018 年 12 月 5 日
"How to improve speed ?"
By following the guidelines in the MATLAB documentation:

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

回答 (1 件)

Stephen23
Stephen23 2018 年 12 月 5 日
編集済み: Stephen23 2018 年 12 月 5 日

0 投票

A = 0.005:0.00005:0.03;
N = numel(A);
M1 = nan(N,4); % max
M2 = nan(N,4); % min
for k = 1:N
...
p = round(max(size(z))/4);
m = z(end-p:end,1:4);
M1(k,:) = max(m,[],1);
M2(k,:) = min(m,[],1);
end
Whether this is really the bottleneck in your code is another matter entirely... have you profiled your code?

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

2018 年 12 月 5 日

コメント済み:

2018 年 12 月 5 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by