when I run my script, all the values are displayed, but I want all the values in vector, so what can I do?
x=[1 2 3 4 5];
y=[1 2 3 4 5];
xx=[1.2 1.6 1.8 2.4 2.8 3.4 4.9 2.6];
yy=[1.2 1.6 1.8 2.5 2.8 3.3 4.9 2.5];
plot(x,y,'.g',xx,yy,'*b')
for j=1:length(xx)
if xx(j)<x(1)
value=0
elseif xx(j) >x(1) & xx(j)<x(2)
value=1
elseif xx(j) >x(2) & xx(j)<x(3)
value=2
elseif xx(j) >x(3) & xx(j)<x(4)
value=3
elseif xx(j) >x(4) & xx(j)<x(5)
value=4
elseif xx(j) >x(5) & xx(j)<x(6)
value=5
else
value= NaN
end
end
value(j)=some_value
and try to avoid usingi
orj
as iterators. Also, consider pre-allocation withvalue = zeros(length(xx),1)
. And also, consider usingnumel
instead oflength
.value
after the loop ends.