필터 지우기
필터 지우기

Finding the maximum value for one graph

조회 수: 20 (최근 30일)
Oskar
Oskar 2017년 12월 15일
댓글: James Knowles 2017년 12월 17일
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)

답변 (1개)

James Knowles
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
Oskar
Oskar 2017년 12월 15일
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 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 CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by