Having hard time plotting groups

I have two sets of group(each group 3 column). I have the mean for each column. I wanted to plot both groups on one graph but i am having hard time understanding the best code to use to get the graph. I am really new to Matlab and would appreciate the help.

11 comentarios

KSSV
KSSV el 8 de Oct. de 2020
Read about plot3, plot, scatter, gscatter.
Mary Johnson
Mary Johnson el 8 de Oct. de 2020
I guess simple question would be, do i graph the mean of each column or all the values of each column?
What is your goal? It would be helpful if you could provide a simple example of what your data look like and what you want your graph to look like.
Are you, for example, trying to plot averaged data of each group so that you have 2 lines, one for each group? One simple way to do this is using stackedplot.
>> t = array2table(reshape(1:36,6,6))
t =
6×6 table
Var1 Var2 Var3 Var4 Var5 Var6
____ ____ ____ ____ ____ ____
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
>> t.Group1Mean = mean(t{:,1:3},2);
>> t.Group2Mean = mean(t{:,4:6},2)
t =
6×8 table
Var1 Var2 Var3 Var4 Var5 Var6 Group1Mean Group2Mean
____ ____ ____ ____ ____ ____ __________ __________
1 7 13 19 25 31 7 25
2 8 14 20 26 32 8 26
3 9 15 21 27 33 9 27
4 10 16 22 28 34 10 28
5 11 17 23 29 35 11 29
6 12 18 24 30 36 12 30
>> stackedplot(t,{["Group1Mean","Group2Mean"]})
Mary Johnson
Mary Johnson el 8 de Oct. de 2020
Okay, so we run 2 different groups under 3 different conditions. In each conditions there are 40 scores. The plot i was trying to have was the first group( 3 column) vs second group(3 remaining column).
Thank you so much.
Mary Johnson
Mary Johnson el 8 de Oct. de 2020
@Seth Furman, i want do the column rather than the rows. How will the code change? Thank you
Attach your data. For example
save('answers.mat', 'x1', 'y1', 'x2', 'y2'); % etc. for as many variables as you have.
Then attach answers.mat with the paper clip icon.
Or else attach your data file with code to read it in.
Mary Johnson
Mary Johnson el 9 de Oct. de 2020
This is the data we collected. We did 2 groups (Test 1 and Test 2). Test 1 were placed under 3 different conditions(Group A, GroupB, and GroupC). Test 2 were placed under 3 different conditions(GroupD,GroupE, and GroupF). I did the mean for each column. The question was to plot the data. The graph was supposed to have Test 1 and Test 2 on same plot. I am sorry i am not doing good in describing the question :(
Star Strider
Star Strider el 9 de Oct. de 2020
Mary Johnson — A picture may be worth a thousand words, however the actual data and code are worth a thousand pictures!
Mary, I'm still a little confused what you mean by "the column rather than the rows".
  • What data do you want for the x-axis?
  • What data do you want for the y-axis?
  • How many plots do you want?
  • Are you looking to plot the data in your screenshot as-is, or do you want to process it before plotting, for example by averaging Groups A through C?
Do you want two adjacent plots, the first with Groups A through C plotted against row index (3 separate lines with 19 points each) and the second with Groups D through F (3 separate lines with 19 points each).
e.g.
>> t = array2table(reshape(1:36,6,6),'VariableNames',strcat("Group",["A" "B" "C" "D" "E" "F"]))
t =
6×6 table
GroupA GroupB GroupC GroupD GroupE GroupF
______ ______ ______ ______ ______ ______
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
>> stackedplot(t,{1:3,4:6})
Mary Johnson
Mary Johnson el 9 de Oct. de 2020
Editada: Mary Johnson el 9 de Oct. de 2020
@Seth Furman, I am wanting the X axis to be the 6 conditions and i want the Y axis the be the mean values. I am wanting the TEST 1(Group A-C) and TEST 2(GroupD-F) both to be on the blot. YES i want to adjust plots. Yes i want to average A through C and D through F. The first plot is supposed to have (condition 1 with Mean column A, condition 2 with Mean column B, condition 3 with Mean column C). The second plot is supposed to be similart to first plot but only from (D-F) in conncected line. Thank you for the help.
Ok. So it sounds like you want something like a bar graph.
Bar graphs can be created with the "bar" function: https://www.mathworks.com/help/matlab/ref/bar.html
I've included an example of the "bar" function below. Please also check out the documentation for plotting, which you may also find helpful:
>> t = array2table(reshape(1:36,6,6),'VariableNames',strcat("Group",["A" "B" "C" "D" "E" "F"]))
t =
6×6 table
GroupA GroupB GroupC GroupD GroupE GroupF
______ ______ ______ ______ ______ ______
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
>> tMean = varfun(@mean,t)
tMean =
1×6 table
mean_GroupA mean_GroupB mean_GroupC mean_GroupD mean_GroupE mean_GroupF
___________ ___________ ___________ ___________ ___________ ___________
3.5 9.5 15.5 21.5 27.5 33.5
>> tiledlayout(2,1);
>> nexttile;
>> x = categorical(t.Properties.VariableNames(1:3));
>> y = tMean{:,1:3};
>> bar(x,y);
>> nexttile;
>> x = categorical(t.Properties.VariableNames(4:6));
>> y = tMean{:,4:6};
>> bar(x,y);

Iniciar sesión para comentar.

 Respuesta aceptada

Mary Johnson
Mary Johnson el 10 de Oct. de 2020
Editada: Mary Johnson el 10 de Oct. de 2020

0 votos

@Seth Ferman, thank you soooo much!!!

Más respuestas (0)

Etiquetas

Preguntada:

el 8 de Oct. de 2020

Editada:

el 10 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by