MATLAB: If statement for a matrix

for loopifloopMATLAB

Hi my x-axis is a 1×72 matrix having values from 1 to 72.
y axis values are again 1×72 matrix having data values.
I want the "if loop" to go on for only those x values which are between 10 and 25, and plot x vs y for only those selected values (y axis data values corresponding to the values between 10 to 25). Could you please evaluate my code.
for i = 1:length(x)
if (x>10) && (x<25)
plot(x,y)
end
end

Best Answer

Use ‘logical indexing’:
x = 1 : 72;
y = rand(1, 72);
mv = (x>10) & (x<25);
figure
plot(x(mv), y(mv))
grid
xlim([min(x) max(x)])
Experiment to get the result you want.