HELP DIFFERENT LINESTYLE ON THE SAME CURVE

Hi everyone, I am a new entry in the group. I have a problem with a matlab plot.
I have two vectors x and y, and plot (x, y), at this point I get a curve. I would like this curve to be dashed for values of x <50 and continuous for values x> 50. how can I do?
Thank you very much for helping

3 commentaires

Matt J
Matt J le 23 Avr 2019
Modifié(e) : Matt J le 23 Avr 2019
I have attached roberta's data here.
Matt J
Matt J le 23 Avr 2019
Modifié(e) : Matt J le 23 Avr 2019
When I plot this data, however, I see something weird-looking that does not look like a function. Perhaps it is not the correct data? Or maybe x and y are interchanged?
roberta perna
roberta perna le 23 Avr 2019
Modifié(e) : roberta perna le 23 Avr 2019
the plot is correct. I would like that x> 50 or 60 ( continuous) and x< 50 or 60 (dashed)

Connectez-vous pour commenter.

 Réponse acceptée

Matt J
Matt J le 23 Avr 2019
Modifié(e) : Matt J le 23 Avr 2019
Just split x,y into two subsets and plot each subset as a separate line:
idx=x<50;
x1=x(idx); y1=y(idx);
x2=x(~idx); y2=y(~idx);
H=plot(x1,y1,'--',x2,y2,'-');

16 commentaires

Matt J
Matt J le 23 Avr 2019
Modifié(e) : Matt J le 23 Avr 2019
For example, with
x=1:100; y=log(x);
idx=x<50;
x1=x(idx); y1=y(idx);
x2=x(~idx); y2=y(~idx);
H=plot(x1,y1,'--',x2,y2,'-');
roberta perna
roberta perna le 23 Avr 2019
sorry I still have problems. I tried but it doesn't work. below I have attached the photos and the code ..
Matt J
Matt J le 23 Avr 2019
Attach your x,y data in a .mat file.
Matt J
Matt J le 23 Avr 2019
Please attach your x,y data in a .mat file. The rest of your code is unnecessary.
Matt J
Matt J le 23 Avr 2019
Modifié(e) : Matt J le 23 Avr 2019
Please attach your x,y data (and nothing else) in a .mat file. The rest of your code is unnecessary. Even if it were necessary, we couldn't run your code, because we lack all the inputs
Undefined function or variable 'DATA_2pi_CO_TW'.
roberta perna
roberta perna le 23 Avr 2019
date and date are files created by fortran that I have in my pc. should I upload them? the problem is at the end of the code.
Walter Roberson
Walter Roberson le 23 Avr 2019
The photos do not seem to have been attached ?
Matt J
Matt J le 23 Avr 2019
No, please just attach a .mat file with the x,y you are trying to plot.
Matt J
Matt J le 23 Avr 2019
Modifié(e) : Matt J le 23 Avr 2019
load myFile
plot(x,y,'--x')
peak=(x>50)&(y>0.5);
line(x(peak), y(peak),'LineStyle','-','LineWidth',3,'Color','red')
ylim([0,2]);
plot.png
roberta perna
roberta perna le 23 Avr 2019
thank you very much
Matt J
Matt J le 23 Avr 2019
You are welcome, but please Accept-click the answer if it resolves your question.
roberta perna
roberta perna le 23 Avr 2019
Is it possible to impose only the limit on x?
Matt J
Matt J le 23 Avr 2019
Meaning?
roberta perna
roberta perna le 23 Avr 2019
Modifié(e) : roberta perna le 23 Avr 2019
this second graph has the same y as the first one. at this point I would like continuous line in the second plot for 0.6471<y<0.797 ( extremes of the continuous line found in the first plot)
I'm not sure I understand, but you can trace a line over any subset of the data using the same kind of technique,
subset=(y<0.797)&(y>0.6471);
line(x(subset), y(subset),'LineStyle','-','LineWidth',3,'Color','red')

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by