How to plot a subset of x,y with group g according to fourth column

3 views (last 30 days)
I have four columns in "data": day, bottle, species, finalC. I am trying to plot finalC as a function of day by group species, but I ONLY want to plot the bottles that are named "BETC". I cannot find anything to help me. I have tried this which doesn't work:
x = data.day
y = data.finalC
g = {data.bottle=="BETC", data.species}
gscatter(x,y,g)

Answers (1)

KSSV
KSSV on 22 Mar 2019
Let day, bottle, species, finalC be your data. I assume them to be columns and bottle is a cell array of strings.
% GEt indices of BETC
idx = contains(bottle,'BETC') ; % if constains not available, use strcmp.
scatter(day(idx),species(idx),10,finalC(idx),'filled')
  1 Comment
Clara Woodie
Clara Woodie on 22 Mar 2019
Thank you for your reply. It did not work however. Bottle is a column in the data file and each row corresponds to an ID such as: BETC, BET, ETC, etc... I want to plot the data only when the rows of this column bottle say BETC. Do you have any more advice? Thanks.

Sign in to comment.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!