How to mark range of Y values in a plot?

조회 수: 14 (최근 30일)
ArcTech
ArcTech 2021년 10월 26일
댓글: ArcTech 2021년 10월 26일
Hello!
I'm trying to generate a plot and place green X symbols over a specific range of places on the Y-Axis. I generated my variables with this code, and plotted them like so:
AStudent=randi(50,1,100);
BStudent=randi(50,1,100);
CStudent=randi(50,1,100);
DStudent=randi(50,1,100);
figure
hold on
plot(AStudent,'b.')
plot(BStudent,'b.')
plot(CStudent,'b.')
plot(DStudent,'b.')
Now I need to try and plot a green X over the existing data on the Y axis between and 25-35. I attempted do do so with the following but this obviously only helps me find the X values. Any idea what I need to do? I'm guessing I have to utalize the "find" function somehow.
hold on
plot([25:35],AStudent(25:35),'gx')
plot([25:35],BStudent(25:35),'gx')
plot([25:35],CStudent(25:35),'gx')
plot([25:35],DStudent(25:35),'gx')
Thank you!

채택된 답변

KSSV
KSSV 2021년 10월 26일
AStudent=randi(50,1,100);
BStudent=randi(50,1,100);
CStudent=randi(50,1,100);
DStudent=randi(50,1,100);
figure
hold on
plot(AStudent,'b.')
plot(BStudent,'b.')
plot(CStudent,'b.')
plot(DStudent,'b.')
hold on
Aidx = AStudent>=25 & AStudent <=35 ;
Bidx = BStudent>=25 & BStudent <=35 ;
Cidx = CStudent>=25 & CStudent <=35 ;
Didx = DStudent>=25 & DStudent <=35 ;
plot(find(Aidx),AStudent(Aidx),'gx')
plot(find(Bidx),BStudent(Bidx),'gx')
plot(find(Cidx),CStudent(Cidx),'gx')
plot(find(Didx),DStudent(Didx),'gx')
  댓글 수: 1
ArcTech
ArcTech 2021년 10월 26일
Thanks! This does exactly what I was looking for.

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

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 10월 26일
Here is one of the viable ways how you can achieve your goal of simulation:
clearvars; close all
k=100; % In case, you need to change the size of your data
AStudent=randi(50,1,k);
BStudent=randi(50,1,k);
CStudent=randi(50,1,k);
DStudent=randi(50,1,k);
%%
figure
N=1:k;
plot(N,AStudent,'ro'), hold on
plot(N,BStudent,'ro')
plot(N,CStudent,'ro')
plot(N,DStudent,'ro')
Idx1 = (AStudent>=25 & AStudent<=35);
Idx2 = (BStudent>=25 & BStudent<=35);
Idx3 = (CStudent>=25 & CStudent<=35);
Idx4 = (DStudent>=25 & DStudent<=35);
hold on
plot(N(Idx1),AStudent(Idx1),'gx')
plot(N(Idx2),BStudent(Idx2),'gx')
plot(N(Idx3),CStudent(Idx3),'gx')
plot(N(Idx4),DStudent(Idx4),'gx')
hold off

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by