how to only plot value0.1 to 0.7 in matlab

To plot values between 0.1 and 0.7 in MATLAB, you can use the following code:

main.m
x = linspace(0, 1, 100);  % Generate a vector of 100 values from 0 to 1
y = sin(2*pi*x);  % Calculate the sine of 2*pi*x

valid_range = (x >= 0.1) & (x <= 0.7);  % Create a logical mask to select values between 0.1 and 0.7
valid_x = x(valid_range);  % Select x values within the range
valid_y = y(valid_range);  % Select y values within the range

plot(valid_x, valid_y);  % Plot the selected values
400 chars
9 lines

In this example, x would be the range of values from 0 to 1, and y could be any function of x. The logical mask valid_range is used to select only the values between 0.1 and 0.7. The selected x and y values are then used to plot the desired range.

Note: Make sure to replace sin(2*pi*x) with your own function or data that you want to plot.

Tags: matlab, plot

related categories

gistlibby LogSnag