Finding the maximum value for one graph

70 views (last 30 days)
Oskar
Oskar on 15 Dec 2017
Commented: James Knowles on 17 Dec 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)

Answers (1)

James Knowles
James Knowles on 15 Dec 2017
Edited: James Knowles on 15 Dec 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 Comments
Oskar
Oskar on 15 Dec 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 on 17 Dec 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.

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!