How to Plot a graph with restriction?

Hi,
I am sorry I am new to MATLAB and dont know how to exactly formulate my quetsion.
I want to plot a graph between two variables but I want to restrict the plot area with a third varible. For example:
x = (0.5*pi:0.1:6*pi) y = sin(x)
Plot (x,y)
but now i want to restrict my plot with the following variable:
z = (pi:0.1;2*pi)
Note: The divisions are same for 'x' and 'z'.
Thanks, Mustahsan

 Risposta accettata

Mustahsan, what do you mean by restrict? Setting the plotting limits? Something like:
xlim([pi, 2*pi])

5 Commenti

Mischa Kim
Mischa Kim il 16 Set 2014
Modificato: Mischa Kim il 16 Set 2014
Use, e.g.,
x = (0.5*pi:0.1:6*pi);
y = sin(x);
z = [pi; 2*pi];
plot(x(x>z(1) & x<z(2)), y(x>z(1) & x<z(2)))
For z you really only need the limits.
Please add follow-up questions and comments as such and not as answers to keep the thread readable.
Sory for replying on the answer section!
Okay following is what i typed, which niether gives me a figure nor a graph
plot(n(n>POS_thr(95) & n<POS_thr(100)), M_ISO(M_ISO>POS_thr(95) & M_ISO<POS_thr(100)))
Where POS_thr is a variable and I want to plot n & M_ISO but with the restriction that POS_thr should only be between 95 and 100.
I hope you get my point!
Since I do not know what your variables are, check out
x = (0.5*pi:0.01:6*pi);
y = sin(x);
z = 2*cos(x).^2;
plot(x,y,x,z)
hold on
plot(x(z>0.5 & z<0.8), y(z>0.5 & z<0.8),'or')
z needs to be within [0.5 0.8] for the second plot.
All the three variables are attached with this reply. All three have same number of rows but I only want to plot 'n' against 'M_ISO' using only those rows where 'POS_thr' is between 95 to 100.
Use
plot(n(POS_thr>=95 & POS_thr<=100), M_ISO(POS_thr>=95 & POS_thr<=100),'or');

Accedi per commentare.

Più risposte (1)

Dear Mustahsan,
not sure if that's what you mean, but please check for
xlim([pi 2*pi])
Best regards, Michael

Community Treasure Hunt

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

Start Hunting!

Translated by