what is another logic that has execution time faster than randi?
Show older comments
here,part of my following code.
clc
clear all
A=8;
B=12;
C=10;
for ii=1:C;
for x=1:2:A-1;
%make first random matrice
[vals RandomMatriceA(x,:,ii)]=sort(rand(1,B),2);
done=false;
while ~done,
%make row of second random matrice
NewRowRandomMatriceB=randi([0 2],1,B);
%Make sure sum all element per row in RandomMatriceB <=11
done=sum(NewRowRandomMatriceB)<12;
end
RandomMatriceB(x,:,ii)=NewRowRandomMatriceB;
...
end
for h=2:2:A;
doneA=false;
while ~doneA,
[vals RandomMatriceA(h,:,ii)]=sort(rand(1,B),2);
doneB=false;
while ~doneB,
NewRowRandomMatriceB=randi([0 2],1,B);
doneB= sum(NewRowRandomMatriceB)<12;
end
RandomMatriceB(h,:,ii)=NewRowRandomMatriceB;
...
end
...
when I tried to use profile viewer to check my code. above part that makes my code took longer time. so, I want suggestion to speed my above code, specially in "randi"
3 Comments
Matt Fig
on 5 Sep 2012
RANDI is a built-in so it is fast. What are you trying to do overall? Perhaps we can help with a different approach.
Febri
on 6 Sep 2012
Matt Fig
on 6 Sep 2012
To run the above code, I have to know what you use for (A,B,C) or the general relation between them. As it is now, the code you pasted above is not running because these are missing....
Accepted Answer
More Answers (0)
Categories
Find more on Code Performance 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!