how to plot values that only fall within a range?

5 次查看(过去 30 天)
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);

采纳的回答

Matt J
Matt J 2020-1-15
编辑:Matt J 2020-1-15
KPH_70 = mean(Y(FVY));
yyaxis left
plot(X(FVY),Y(FVY));
yyaxis right
plot(X(FVY),KPH_70*ones(size(FVY)));
  17 个评论
Matt J
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)),'-' )
untitled.png

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by