필터 지우기
필터 지우기

How to normalize two waves on a single plot

조회 수: 1 (최근 30일)
Lakerpurp24
Lakerpurp24 2019년 9월 11일
댓글: Star Strider 2019년 9월 11일
Basically i want to normalize and display the maximum and minimum values between y and y2 for the following code so that they both display on the same plot
t=0:0.001:0.05;
y= 11.18*cos(60*pi*t+26.565);
y2= -60*pi*11.18*sin(60*pi*t+26.565);
title('Phasor Waveforms')
f1=max(y);
f2=max(y2);
hold on
plot(t,y)
plot(t,y2)
hold off

채택된 답변

Star Strider
Star Strider 2019년 9월 11일
Try this:
t=0:0.001:0.05;
y= 11.18*cos(60*pi*t+26.565);
y2= -60*pi*11.18*sin(60*pi*t+26.565);
title('Phasor Waveforms')
f1=max(y);
f2=max(y2);
figure
yyaxis left
plot(t,y)
yyaxis right
plot(t,y2)
See the documentation for yyaxis (R2016a and later releases, earlier releases plotyy, and different code) for details.
  댓글 수: 3
Star Strider
Star Strider 2019년 9월 11일
As always, my pleasure!
I’m not sure what you want to do.
Try this:
t=0:0.001:0.05;
y= 11.18*cos(60*pi*t+26.565);
y2= -60*pi*11.18*sin(60*pi*t+26.565);
title('Phasor Waveforms')
f1=max(y);
f2=max(y2);
idymax = find(y == max(y));
figure
yyaxis left
plot(t,y)
hold on
plot(t(idymax),y(idymax),'o','MarkerFaceColor','red','MarkerSize',15)
hold off
yyaxis right
plot(t,y2)
If you want to plot a point or a series of values, the subscripts for those values need to be the same for all coordinates.
The find function will return the indices of all the values that are equal to ‘max(y)’ here. If there is only one ‘y’ maximum, an alternative could be:
[f1,idymax]=max(y);
since the max function will return the index to the first maximum it discovers.
Star Strider
Star Strider 2019년 9월 11일
If you assign that logical operation to a variable it returns a logical vector of false (0) values, except for the maximum (true,1) to the variable:
q = y == max(y)
Otherwise, without the assignment, it does not appear to do the logical operation. (I did that experiment.)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2019년 9월 11일
t=0:0.001:0.05;
y= 11.18*cos(60*pi*t+26.565);
y2= -60*pi*11.18*sin(60*pi*t+26.565);
title('Phasor Waveforms')
y=y/max(y) ;
y2=y2/max(y2) ;
[f1,idx1]=max(y);
[f2,idx2]=max(y2);
hold on
plot(t,y)
plot(t,y2)
plot(t(idx1),f1,'*r')
plot(t(idx2),f2,'*b')
hold off

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by