Having hard time plotting groups
Mostrar comentarios más antiguos
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
el 8 de Oct. de 2020
Read about plot3, plot, scatter, gscatter.
Mary Johnson
el 8 de Oct. de 2020
Seth Furman
el 8 de Oct. de 2020
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
el 8 de Oct. de 2020
Mary Johnson
el 8 de Oct. de 2020
Image Analyst
el 8 de Oct. de 2020
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
el 9 de Oct. de 2020
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!
Seth Furman
el 9 de Oct. de 2020
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
el 9 de Oct. de 2020
Editada: Mary Johnson
el 9 de Oct. de 2020
Seth Furman
el 9 de Oct. de 2020
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);

Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Power Converters en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!