ismember matlab function too slow
古いコメントを表示
Hi, I would love some help optimizing this piece of code.
In my model i have to go every time instant through all the pixels of an image ( this cannot be changed to solve the equations that I want).
At a given step I want to now if a given pixel corresponds to the list of upetake indexes (uptake_indices) or not. If so I would have a concentration = uptake, else it would be 0.
Currently I am using ismember, but since my arrays are big and the loops are really long, this step delays a lot my code.
Here is a pice of my code.
Thanks for the help!
% list of indexes of my 400x400 image
aux=1;
pareja_indice=zeros(400*400,1);
for i=1:400
for j=1:400
pareja_indice(aux) = sub2ind([400, 400], i, j);
aux=aux+1;
end
end
% Load indexes corresponding to uptake points in the image
load('GABA_uptake_points3.mat');
uptake_indices = sub2ind([400, 400], SourceY, SourceX);
aux=0;
uptake=30;
% initialize concentration matrix
C=zeros(400,400);
for k=1:2000000
% other operations
for i=1:400
for j=1:400
aux=aux+1;
% we should only have uptake at the uptake locations
C_up = uptake * ismember(pareja_indice(aux), uptake_indices);
C(i,j)=C_up;
% ... other operations
end
end
% other operation
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および 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!