I am trying to plot the maximum value onto my subplot
x=linspace(0,L,1000);
V= R.*(x>0).*(x-0).^0 - (w).*(x>a).*(x-a).^1 - F1.*(x>b).*(x-b).^0 + (w).*(x>c).*(x-c).^1 + R.*(x>L).*(x-L).^0;
subplot(4,2,1);
area(x,V);
ylabel('V_y (N)');
ylim([min([1.2*min(V),0,-1.2*min(V)]),max([0,1.2*max(V),-1.2*max(V)])]);
xlim([0,1.2*L])
[Vmax i]=max(V)
xmaxV=x(i)

 Réponse acceptée

I don't have your data, but one way to do it is to use hold on so both the area and the point are shown simultaneously, and put a marker on your point so you can see it:
L = 100;
x = linspace(0,L,1000);
V = 2500-(x-50).^2;
area(x,V);
[Vmax i]=max(V)
Vmax = 2.5000e+03
i = 500
xmaxV=x(i)
xmaxV = 49.9499
hold on
plot(xmaxV,Vmax,'o','MarkerFaceColor','r','MarkerSize',20)

5 commentaires

Andrew Maxey
Andrew Maxey le 11 Fév 2022
so i tried that, and when i do it gives me this
Unrecognized function or variable 'xmaxV'.
Error in ME466_2_quiz2 (line 40)
plot(xmaxV,Vmax,'o','MarkerFaceColor','r','MarkerSize',20)
What's the output to the command line when the previous two lines run?
[Vmax i]=max(V)
xmaxV=x(i)
Is there a typo somewhere, e.g., XmaxV or xmaXv, etc.?
Andrew Maxey
Andrew Maxey le 11 Fév 2022
I haven gone over it multiple times and cant find a typo, but this is the ouput it is giving me
Vmax =
1675
i =
2
xmaxV =
0.0010
Andrew Maxey
Andrew Maxey le 11 Fév 2022
Your answer to my question was correct, I realized I called for the function before defining it.
Voss
Voss le 11 Fév 2022
Glad you got it to work!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by