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 件のコメント
isamh
2020 年 1 月 15 日
didn't work, i uploaded the plot and still shows values that are below the 111
isamh
2020 年 1 月 15 日
never mind Matt it does filter the values that lie outside the range. only issue is the average curve.
Matt J
2020 年 1 月 15 日
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?
isamh
2020 年 1 月 15 日
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);
isamh
2020 年 1 月 15 日
didn't work, i'll firgure it out someway. Thanks so much for the help Matt!
Matt J
2020 年 1 月 15 日
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.
isamh
2020 年 1 月 15 日
how would i be able to do that? kind new to matlab
Matt J
2020 年 1 月 15 日
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)),'-' )
Matt J
2020 年 1 月 15 日
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)),'-' )

isamh
2020 年 1 月 15 日
works great, Thanks so much!!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Graphics Objects についてさらに検索
タグ
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
