How do I calculate the difference between the elements of two vectors given a condition ?

6 Ansichten (letzte 30 Tage)
Please, how do I implement this on MATLAB? I would like to find the difference between the value of let say x3 minus the maximum value of y that fulfils the condition x3>= y(--)? For example, if x= [106, 306, 407, 607, ...] and y = [101, 201, 301, 401, 501,...], at x(3), this difference will be 407 - 401 (401 is the max value less than x(3)).
for i= 1: 100
x = [x1,x2,x3,...]
y= [y1,y2,y3,...]
Time = %the difference between the value of let say x3 minus the maximum value of y that fulfils the condition x3>= y(--)?
end

Akzeptierte Antwort

RAMAKANT SHAKYA
RAMAKANT SHAKYA am 25 Feb. 2019
for given vector x and y;
x= [106, 306, 407, 607] % given x vector
y = [101, 201, 301, 401, 501] %givrn y vector
d=[];
for ii=1:length(x)
for jj=1:length(y)
if x(ii)>=y(jj)
d=[d,y(jj)]; %vector of all elements which is less than x say X(3)
end
end
diff=x(ii)-max(d); %differnece
d=[];
end

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by