Finding the maximum value for one graph
72 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
James Knowles
2017-12-15
编辑:James Knowles
2017-12-15
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 个评论
James Knowles
2017-12-17
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!