Azzera filtri
Azzera filtri

Finding the maximum value for one graph

21 visualizzazioni (ultimi 30 giorni)
Oskar
Oskar il 15 Dic 2017
Commentato: James Knowles il 17 Dic 2017
In my code I have created 2 graphs, I need to find the maximum y values in both graphs and I'm unsure how to do that, at the moment my code gives the same 2 maximum y values from the second graph, rather than showing the 2 maximum values from each graph. This is the code:
clear all;
time_period = [0 181324/20000];
initial = [0, 0];
[t,y]=ode45(@myode45function, time_period, initial);
plot(t,y(:,1)),title('Graph of y against t')
xlabel('t')
ylabel('y')
ymax=max(y);
disp(ymax)
figure
plot(t,y(:,2)),title('Graph of dy/dt against t')
xlabel('t')
ylabel('dy/dt')
ymax1=max(y);
disp('The maximum value of dy/dt is: ')
disp(ymax1)

Risposte (1)

James Knowles
James Knowles il 15 Dic 2017
Modificato: James Knowles il 15 Dic 2017
I believe this is what you are after. The plots are irrelevant, the range of y you wish to find the maximum for just needs to be specified. For example
nx = 1:50;
ny = 1:50;
x = rand(50,50);
y = rand(50,50);
figure;
plot1 = plot(nx,x(:,1));
figure;
plot2 = plot(ny,y(:,2));
max_x = max(x(:,1));
max_y = max(y(:,2));
  2 Commenti
Oskar
Oskar il 15 Dic 2017
I am a bit confused by your answer (I'm new to matlab sorry). What does the nx and ny mean? and also the rand(50,50) what does that do?
James Knowles
James Knowles il 17 Dic 2017
my apologies, nx and ny are just names of variables that I have made up.
'rand' is an inbuilt function which makes a random value between 0 and 1. In this case I have made a 50X50 matrix of these random numbers.
In your case to find the maximums of each plot; ymax = max(y(:,1)) and ymax1 = max(y(:,2)) will find the maximum values for each plot.

Accedi per commentare.

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by