Help on ploting bar graph using table
조회 수: 13(최근 30일)
표시 이전 댓글
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);
채택된 답변
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
figure
bar(T{2,:})
set(gca, 'XTick',1:numel(newNames), 'XtickLabel',newNames)
.
댓글 수: 8
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
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...
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!