How to mark range of Y values in a plot?

16 visualizzazioni (ultimi 30 giorni)
ArcTech
ArcTech il 26 Ott 2021
Commentato: ArcTech il 26 Ott 2021
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!

Risposta accettata

KSSV
KSSV il 26 Ott 2021
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')

Più risposte (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov il 26 Ott 2021
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

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by