How do I use the values in a .txt file to create a stacked bar graph?

I've already been successful at opening the file and obtaining the values
fileID = fopen('report_data.txt','r');
patientName=fgetl(fileID);
dateOfBirth=fgetl(fileID);
notes=fgetl(fileID);
healthy_exposed = fgetl(fileID);
pus = fgetl(fileID);
necrotic = fgetl(fileID);
ulcer_stage = fgetl(fileID);
area = fgetl(fileID);
volume = fgetl(fileID);
fclose(fileID);
But I'd like to take healthy_exposed, pus, and necrotic and create a stacked bar graph.

回答(1 个)

bar( [str2num(healthy_exposed)', str2num(pus)', str2num(necrotic)'], 'stacked')

4 个评论

It produces this error:
Error using cat
Dimensions of matrices being concatenated are not consistent.
Error in clinrep (line 49)
bar(cat(1, healthy_exposed, pus, necrotic), 'stacked');
You must convert your data to numeric type first. fgetl returns charactor type. Use str2num to convert it to numeric type. You might be getting this error because of strings of unequal length.
Hey Dishant, I did recently use str2num actually.
figure;
bar(cat(1, str2num(healthy_exposed), str2num(pus), str2num(necrotic)), 'stacked');
The result is this. It failed to produce a 'stacked' bar graph.
I was wrong on my part. I have made appropriate changes in the answer.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Discrete Data Plots 的更多信息

提问:

2014-3-26

Community Treasure Hunt

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

Start Hunting!

Translated by