How to get a vectorized Matrix with conditions?
Show older comments
I am using matlab,the processing time is very big about three hours to four hours for each test. This is my code:
for a=1:6
for i= 1:16384
for j= 1:16384
if i==j
MH(i,j)= V(i)+NV(i)*VP(a);
else
%appartenance de j
x=cp(j,1);
y=cp(j,2);
ii=-1;
while ii<7
ii=ii+2;
iii=ii+1;
if VI(i,ii)==x && VI(i,iii)==y
voisin=1;
else
voisin= 0;
end
if voisin==1
MH(i,j)=VP(a);
else MH(i,j)=0;
end
end
end
end
end
end
Can you please help to get my matrix vectorized
How to get a matrix vectorized in matlab with conditions? - ResearchGate. Available from: https://www.researchgate.net/post/how_to_get_a_matrix_vectorized_in_matlab_with_conditions [accessed Dec 9, 2015].
2 Comments
Torsten
on 9 Dec 2015
I can't believe this part of your code really does what you want.
ii=-1;
while ii<7
ii=ii+2;
iii=ii+1;
if VI(i,ii)==x && VI(i,iii)==y
voisin=1;
else
voisin= 0;
end
if voisin==1
MH(i,j)=VP(a);
else
MH(i,j)=0;
end
end
Note that the value of MH(i,j) depends on the order (in ii) in which you check whether
VI(i,ii)==x && VI(i,ii+1)==y
Best wishes
Torsten.
sarah
on 9 Dec 2015
Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!