how to plot values that only fall within a range?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
have an excel file where i am plotting the values that are around 113 KPH. there are thousands of rows for that specifc column and i just wanna plot the Y values that fall between 111KPH and 114 KPH. I also am trying to add the average of those data points but that doesnt seem to work as well. I attached the plot which is incorrect and for some reason is between 0 and 1.
code is:
%%% 70 MPH KPH vs Time
filename = 'TeslaData_Coastdown Analysis_7_26_2019.xlsx';
figure(1)
X = xlsread(filename,'70 MPH','A9:A2000');%adjust according to column length
Y = xlsread(filename,'70 MPH','B9:B2000');%adjust according to column length
FVY = (Y >= 111 & Y <= 114)
KPH_70 = mean(FVY);
yyaxis left
plot(X,FVY);
yyaxis right
plot(X,KPH_70);
채택된 답변
KPH_70 = mean(Y(FVY));
yyaxis left
plot(X(FVY),Y(FVY));
yyaxis right
plot(X(FVY),KPH_70*ones(size(FVY)));
댓글 수: 17
didn't work, i uploaded the plot and still shows values that are below the 111
never mind Matt it does filter the values that lie outside the range. only issue is the average curve.
only issue is the average curve.
What is the issue?
as shown in the plot, the average curve doesn't aling with the filtered data.
i edited the code you submitted as well.
KPH_70 = mean(Y(FVY));
yyaxis left
plot(X(FVY),Y(FVY));
yyaxis right
plot(X(FVY),KPH_70);
what exactly does this *ones(size(FVY))); mean?
I assumed you want a horizontal line marking the mean across Y(FVY) and that's what your attached plot seems to show. If that's not what you want, what should it be?
that's exactly what I want but would there be a way to make both axis line up? Thanks for the help, really appreciate it!
You mean so that the two y-axes span the same range? Here's one way,
KPH_70 = mean(Y(FVY));
yyaxis left
plot(X(FVY),Y(FVY));
yl=ylim;
yyaxis right
plot(X(FVY),KPH_70*ones(1,nnz(FVY)),'-' )
ylim(yl);
didn't work, i'll firgure it out someway. Thanks so much for the help Matt!
I think I fixed it. However, I don't really understand why you have two y-axes as opposed to putting multiple plot lines on a single y-axis.
how would i be able to do that? kind new to matlab
Just by doing
plot(X(FVY),Y(FVY), X(FVY),KPH_70*ones(size(FVY)) );
i tried this earlier but only one curve shows. not sure why, when it comes to the KPH_70 , nothing happens.
also, what does *ones(size(FVY)) mean?
I'm really sorry for asking so many questions!
also, what does *ones(size(FVY)) mean?
It creates a vector of ones the same size as FVY, e.g.,
>> FVY=rand(1,5)
FVY =
0.8184 0.3599 0.3480 0.2924 0.0110
>> ones(size(FVY))
ans =
1 1 1 1 1
i tried this earlier but only one curve shows.
Seems doubtful that you tried exactly what I've shown. If you didn't know what ones(size(FVY)) even means, how would it have occurred to you to try it?
haven't tried that specifically. I tried to plot(X,FVY,X,KPH_70) and get same results as
plot(X(FVY),Y(FVY), X(FVY),KPH_70*ones(size(FVY)) );. what's important is that both don't work. Also, when I try *ones(size(FVY)) command window says that they aren't the same length.
I'll manage with what I have right now, hopefully i'll figure it out tonight.
thanks for everything Matt!
Sorry, it should be
plot(X(FVY),Y(FVY),'x--', X(FVY),KPH_70*ones(1,nnz(FVY)),'-' )
Here is an example,
X=1:10;
Y=rand(size(X));
FVY=X>3;
KPH_70=mean(Y(FVY));
plot(X(FVY),Y(FVY),'x--', X(FVY),KPH_70*ones(1,nnz(FVY)),'-' )

works great, Thanks so much!!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Graphics Objects에 대해 자세히 알아보기
태그
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
