Greetings dear friends, I am trying to plot a bar chart for a set of twelve data in x and twelve data in y, but I think I am making a mistake in the use of some command, I appreciate your help:
This is my interface with each name:
This is my code:
x=[6,12,20,30,40,50,70,100,140,200,270,300];
y13=str2double(app.EditField_12.Value);
y14=str2double(app.EditField_13.Value);
y15=str2double(app.EditField_14.Value);
y16=str2double(app.EditField_15.Value);
y17=str2double(app.EditField_16.Value);
y18=str2double(app.EditField_17.Value);
y19=str2double(app.EditField_18.Value);
y20=str2double(app.EditField_19.Value);
y21=str2double(app.EditField_20.Value);
y22=str2double(app.EditField_21.Value);
y23=str2double(app.EditField_22.Value);
y24=str2double(app.EditField_23.Value);
y=[y13,y14,y15,y16,y17,y18,y19,y20,y21,y22,y23,y24];
%ref=sum(y)
%axes(app.histo);
bar(app.histo,x,y,1,'histc')
grid on
And I get this (for certain y-values):
Thank you very much for your help!

 Réponse acceptée

VBBV
VBBV le 25 Mai 2023
bar(app.histo,x,y)
Try only using the above arguments. I think you want some histogram to be plotted , in that case use histogram function instead of bar

5 commentaires

Lewis HC
Lewis HC le 25 Mai 2023
Thank you very much for the advice, the same results continue :/
Try using the xticklabels function to make x-axis values display in uniform manner, since the x values are scattered and not continous for the corresponding input y-values
x=1:12;
xt = {'6','12','20','30','40','50','70','100','140','200','270','300'};
% y13=str2double(app.EditField_12.Value);
% y14=str2double(app.EditField_13.Value);
% y15=str2double(app.EditField_14.Value);
% y16=str2double(app.EditField_15.Value);
% y17=str2double(app.EditField_16.Value);
% y18=str2double(app.EditField_17.Value);
% y19=str2double(app.EditField_18.Value);
% y20=str2double(app.EditField_19.Value);
% y21=str2double(app.EditField_20.Value);
% y22=str2double(app.EditField_21.Value);
% y23=str2double(app.EditField_22.Value);
% y24=str2double(app.EditField_23.Value);
% y=[y13,y14,y15,y16,y17,y18,y19,y20,y21,y22,y23,y24];
% some randome input data
y = rand(1,12);
%ref=sum(y)
%axes(app.histo);
% bar(app.histo,x,y,1,'histc')
% you can use the app designer handle below line
bar(x,y)
xticklabels(xt)
grid on
Lewis HC
Lewis HC le 25 Mai 2023
Thank you for your help, the problem is that with x=[6,12,20,30,40,50,70,100,140,200,270,300]; and y=[y13,y14,y15,y16,y17,y18,y19,y20,y21,y22,y23,y24]; I have to create the histogram or bar chart in the window named app.histo (attached):
VBBV
VBBV le 25 Mai 2023
Modifié(e) : VBBV le 25 Mai 2023
Ok. You can use the app function handle like you did before. And also add the xticklabels command as i shown.
For demonstration purposes i have commented it. Can you share the app code
This is my code dear friend, but it does not work:
x=[6,12,20,30,40,50,70,100,140,200,270,300];
y13=str2double(app.EditField_12.Value);
y14=str2double(app.EditField_13.Value);
y15=str2double(app.EditField_14.Value);
y16=str2double(app.EditField_15.Value);
y17=str2double(app.EditField_16.Value);
y18=str2double(app.EditField_17.Value);
y19=str2double(app.EditField_18.Value);
y20=str2double(app.EditField_19.Value);
y21=str2double(app.EditField_20.Value);
y22=str2double(app.EditField_21.Value);
y23=str2double(app.EditField_22.Value);
y24=str2double(app.EditField_23.Value);
y=[y13,y14,y15,y16,y17,y18,y19,y20,y21,y22,y23,y24];
%ref=sum(y)
%axes(app.histo);
bar(app.histo,x,y,1,'histc')
grid on
It should be noted that:
1. The values of x are fixed
2. The values of y13 to y24 are percentages.
3. The histogram in the matlab app designer interface is called app.histo (the histogram or bar chart should appear in this graphical interface).

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by