Effacer les filtres
Effacer les filtres

Sir I want to know how to draw multiple curves in matlab without using the sine function

1 vue (au cours des 30 derniers jours)
I want to draw curves not straight lines. Kindly help me. If I use the linspace function it asks me function, but I only have values instead of that.
I want to draw multiple curves without using function. I have these values how to plot a smooth curves
[-.7 .35 -.35 1.4]
[-.9 0 -.4 .96]
[-1.1 -.07-.5 .8]
[0 30 60 90]

Réponses (2)

Star Strider
Star Strider le 12 Fév 2017
See if this does what you want. It uses ‘pchip’ interpolation, not the sine function. For more details, see the documentation for the interp1 function.
The Code
y = [[-.7 .35 -.35 1.4]
[-.9 0 -.4 .96]
[-1.1 -.07 -.5 .8]];
x = [0 30 60 90];
xi = [0:0.5:90];
yi = interp1(x', y', xi, 'pchip');
figure(1)
plot(x, y, 'pk')
hold on
plot(xi, yi, '--k')
hold off
grid
The Plot
  3 commentaires
Image Analyst
Image Analyst le 12 Fév 2017
There are 181 points there. He just didn't plot them all because there are so many and they're so close together they're hard to see. Try this change:
plot(xi, yi, '--.k', 'MarkerSize', 10)
and maximize the figure to full screen. You'll be able to see lots of points in between the original 4 training points.
Star Strider
Star Strider le 12 Fév 2017
@has mein — What do you intend with ‘gives me grid do not gives grid off points’? The ‘yi’ variable is a matrix of interpolated points matching your original matrix (transposed, since interp1 wants column vectors, and you can easily transpose them again to match your original matrix).
Please explain what you want in more detail.
@Image Analyst — Thank you!

Connectez-vous pour commenter.


Abhay Mohan
Abhay Mohan le 12 Fév 2017
Any curve in matlab is essentially obtained by joining straight lines. This is because MATLAB only has discrete values as it has limited memory. Continuous functions require infinite memory. however, you can make the curve look continuous if you have enough samples. If you already have data points, to get a smooth curve, you will have to interpolate it using the curve fitting tool. To use this, first enter the x and y data as variables. Then use the cftool command to launch curve fitting toolbox. How to use this is explained here .
  1 commentaire
Image Analyst
Image Analyst le 12 Fév 2017
has mein's "Answer" moved here since it's a comment to the above answer, not an answer itself:
Thank you for your reply sir, but I want to create multiple curves not a single curve. Since it was in my project I am struggling for that. Using curve fitting I can't fit multiple curves. Anyway thanks for your humble reply in this late night. Thank you so much. Using hold on option also can't help me.

Connectez-vous pour commenter.

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by