Finding the maximum value for one graph
70 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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)
0 Kommentare
Antworten (1)
James Knowles
am 15 Dez. 2017
Bearbeitet: James Knowles
am 15 Dez. 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 Kommentare
James Knowles
am 17 Dez. 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.
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!