Hello, I wrote following lines for plotting a bar graph of shock1-shock5 excel files.
%filename='shock1-5.xlsx'
clear all
clc
training=5;
sheetname='Result';
for i=1:training
disp(i)
freezePercent=xlsread(strcat('shock',num2str(i)),'C2:C11');
for j=1:length(freezePercent)
bar(freezePercent,'grouped')
hold on
end
end
However my code returns me stacked bar graph which looks like this.
I want mine to look like this:

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 1 de Jun. de 2020

0 votos

Try this
clear all
clc
training=5;
sheetname='Result';
freezePercent = zeros(training, 10);
for i=1:training
freezePercent(i,:)=xlsread(strcat('shock',num2str(i)),'C2:C11');
end
bar(freezePercent)

6 comentarios

Yanjika O
Yanjika O el 2 de Jun. de 2020
Hey! this works perfect. Thanks a lot.
Ameer Hamza
Ameer Hamza el 2 de Jun. de 2020
I am glad to be of help!
Yanjika O
Yanjika O el 2 de Jun. de 2020
But, what if I want to plot them individually?
Ameer Hamza
Ameer Hamza el 2 de Jun. de 2020
Can you show an example of how to plot individually? Can you share a sample dataset?
Yanjika O
Yanjika O el 2 de Jun. de 2020
Hey I wanted to plot the groups individually in a separate graphs. I became able to do what I wanted with the following code:
clear all
clc
training=5;
sheetname='Result';
%freezePercent = zeros(training, 10);
for i=1:training
freezePercent(i,:)=xlsread(strcat('shock',num2str(i)),'Result','C2:C11');
averageLine(i,:)=xlsread(strcat('shock',num2str(i)),'Result','C12');
figure(i)
bar(freezePercent(i,:))
hold on
%line([1,10],[averageLine,averageLine])
%hold on
end
Thanks you for your responses!
Ameer Hamza
Ameer Hamza el 2 de Jun. de 2020
Glad that you found the solution. You may also see subplot() to draw them on the same figure.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 1 de Jun. de 2020

Comentada:

el 2 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by