random matrix with a minimum number difference for adjacent numbers accepted
Ältere Kommentare anzeigen
Dear all,
I come to you with a problem I am facing right now. I am trying to make a random matrix with adjacent numbers that have to be at leat min_diff different from one another.
For now, I tried making the code below, but it seem to be flawed as I found 5.3268 5.2605 as adjacent numbers in my last try.
max=6;
min=3;
bounds=[min,max];
min_diff=0.1;
X=zeros(1,1250);
R=rand(1,size(X,2))*range(bounds)+bounds(1);
R1=zeros(size(R));
tcount=0;%just to know the number of itteration
for i=1:length(R)
R1(:,i)=ismembertol(R(:,i),R(:,i-1>0),min_diff);
while R1(:,i)==1
tcount=tcount+1;
R(:,i)=R(:,i)+min_diff;
R1(:,i)=ismembertol(R(:,i),R(:,i-1>0),min_diff);
end
end
Thank you in advance for your help,
JdC
Akzeptierte Antwort
Weitere Antworten (1)
Why not as follows?
min_diff=0.1;
R=rand(1,6);
R=R./min(abs(diff(R)))*min_diff;
abs(diff(R))
2 Kommentare
JdC
am 19 Jan. 2022
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!