Histogram in App Designer

So I have this excel file and i want to make an histogram or scatter in app desginer for smoke and non smoker, can someone help me out ? I can't figure it out, because in the excel Smoker is just one column, and i want to make a histogram with 2 bars (different colours), one is for the smokers, and the other one is for non smokers.

9 件のコメント

Rik
Rik 2020 年 7 月 3 日
The first step is to get your data into Matlab. How did you do that? What is the next step?
Diogo Costa
Diogo Costa 2020 年 7 月 3 日
編集済み: Diogo Costa 2020 年 7 月 3 日
I already did that, i am quite comfortable with matlab, but this histogram is getting my head tired...
Plus i got also a graphic of systolic and age.
I only need now the histogram..
handles.fileName = uigetfile('Pacientes.xlsx');
t = readtable("Pacientes.xlsx","Sheet",1);
app.UITable.Data = t;
x = table2array(t(:,"Systolic"));
y = table2array(t(:,"Age"));
plot(app.UIAxes,y,x);
Diogo Costa
Diogo Costa 2020 年 7 月 3 日
So i figure it out, thanks anyway :)
t = readtable("Pacientes.xlsx","Sheet",1);
x = table2array(t(:,"Smoker"));
C = categorical(x,[1 0],{'Smoker','Non Smoker'})
h = histogram(app.UIAxes2,C,'BarWidth',0.5)
Rik
Rik 2020 年 7 月 3 日
Feel free to move your solution to the answer section.
For next time you can also separately calculate the histcounts and then plot the frequencies as a bar chart.
Diogo Costa
Diogo Costa 2020 年 7 月 3 日
But i have another problem now, i can't figure it out how to change the colors or the bars with that code, i didn't add anything, can you try help me ?
Rik
Rik 2020 年 7 月 3 日
And that is why I tend to use histcounts. Have you tried reading the documentation for the histogram function to see what properties you can modify?
Diogo Costa
Diogo Costa 2020 年 7 月 3 日
Sure, i saw that we can change the color, but i'm working in app designer so it's a bit different, i tried 'FaceColor' but I can't make the tow bars look in diferent colors
Diogo Costa
Diogo Costa 2020 年 7 月 3 日
So I have this, but only turns the bars in red, and that's is not what i want, i want each bar with each color
t = readtable("Pacientes.xlsx","Sheet",1);
app.UITable.Data = t;
x = table2array(t(:,"Smoker"));
C = categorical(x,[1 0],{'Smoker','Non Smoker'})
h = histogram(app.UIAxes2,C,'BarWidth',0.5,'FaceColor',"r")
legend(h(:), {'Smoker' 'Non Smoker'},'Location','northwest')
Rik
Rik 2020 年 7 月 3 日
I don't think that is possible with histogram, so you will have to create two bar objects.

サインインしてコメントする。

回答 (1 件)

Harry Smith
Harry Smith 2022 年 6 月 18 日

1 投票

This may help:
histogram(app.histogramPlot,data)

1 件のコメント

Gligan Miron Marius
Gligan Miron Marius 2023 年 5 月 18 日
Yes, in my case it works correctly.
...
I_hist=histogram(app.Hist, I_rgb);
...

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

質問済み:

2020 年 7 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by