Help on ploting bar graph using table

13 ビュー (過去 30 日間)
gurjeevan singh
gurjeevan singh 2022 年 5 月 15 日
コメント済み: dpb 2022 年 5 月 16 日
Dear Sir/Madam,
Im having difficulty plotting my data in my table to a bar graph. I have renamed my columns of my table and wish to plot a bar graph of the data with the column heading under each bar. Im a beginner in matlab and Ive had a look at the bar help website, but cant seem to solve my issue
Im getting the error: Input arguments must be numeric, datetime, duration or categorical.
I would greatly appreciate help on my problem. Thank You in advance
Best Regards,
Jeevs S
newNames={'Protein A','Protein B','Protein C','Protein D','Protein E','Protein F','Protein G'...
,'Protein H','Protein I','Protein J','Protein K','Protein L''Protein M','Protein N','Protein O','Protein P',...
'Protein Q','Protein R','Protein S','Protein T','Protein U','Protein V'};
T=array2table(data1, 'VariableNames', newNames);
bar(T);
  2 件のコメント
gurjeevan singh
gurjeevan singh 2022 年 5 月 16 日
Dear dpd,
Apologies for the error in the data table. I have updated the data, given by 'data2'
T=readtable('data2.xlsx');
head(T);
Thank you for having a look at my problem
Jeevs S

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

採用された回答

Star Strider
Star Strider 2022 年 5 月 15 日
There are mismatches between the number of names and the number of variables, and a missing comma between ‘Protein L’ and ‘Protein M’. I am not certain what the first row is for, or how to use it here, since if used with bar3, it dominates the plot .
Anyway, try this —
T = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/999080/data1.xlsx');
T{:,end+1} = [22; rand*1E-4]; % Add Variable So That Everything Works
newNames={'Protein A','Protein B','Protein C','Protein D','Protein E','Protein F','Protein G'...
,'Protein H','Protein I','Protein J','Protein K','Protein L','Protein M','Protein N','Protein O','Protein P',...
'Protein Q','Protein R','Protein S','Protein T','Protein U','Protein V'};
T.Properties.VariableNames = newNames
T = 2×22 table
Protein A Protein B Protein C Protein D Protein E Protein F Protein G Protein H Protein I Protein J Protein K Protein L Protein M Protein N Protein O Protein P Protein Q Protein R Protein S Protein T Protein U Protein V __________ __________ _________ _________ _________ _________ __________ _________ __________ __________ _________ __________ _________ _________ _________ _________ __________ _________ __________ __________ _________ __________ 1 2 NaN 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 0.00011099 0.00019448 0.0001 0 0 0 9.6679e-05 0 0.00026839 0.00023922 0 0.00019448 0.0001 0 0 0 9.6679e-05 0 0.00026839 0.00023922 0 1.9708e-05
figure
bar(T{2,:})
set(gca, 'XTick',1:numel(newNames), 'XtickLabel',newNames)
.
  8 件のコメント
dpb
dpb 2022 年 5 月 16 日
Attach a representative section of the dataset...there still may be "more better" ways to import/use it...we can only see through a tiny peephole here.

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

その他の回答 (1 件)

dpb
dpb 2022 年 5 月 16 日
編集済み: dpb 2022 年 5 月 16 日
Pursuant to the previous comments; my suggestions would result in something like
>> tSinghBar=readtable('data2.xlsx');
>> tSinghBar.Protein=categorical(tSinghBar.Protein)
tSinghBar =
20×2 table
Protein Measure1
_______ __________
A 0.00011099
B 0.00019448
C 0.0001
D 0
E 0
F 0
G 9.6679e-05
H 0
I 0.00026839
J 0.00023922
K 0
L 0.00019448
M 0.0001
N 0
O 0
P 0
Q 9.6679e-05
R 0
S 0.00026839
T 0.00023922
>> bar(tSinghBar.Protein,tSinghBar.Measure1)
>>
I attached the updated/reformatted Excel file for your convenience/viewing pleasure...

Community Treasure Hunt

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

Start Hunting!

Translated by