Plotting bar graph using loop

5 ビュー (過去 30 日間)
Nada Zamri
Nada Zamri 2016 年 10 月 26 日
コメント済み: Mostafa 2016 年 10 月 27 日
Hi, may I know how to plot bar graph that can show how many people are in the range of 0.00 to 0.30 and how many people are within range 0.30 to 0.50 and those exceeding 0.50. I tried using these commands but it does not work.
filename=('Book 1'); A=xlsread(filename,'Sheet 1'); A(isnan(A))=0; y1=(A(1:8,2)); % x axis position y2=(A(1:8,3)); % y axis position y3=(A(1:8,4)); % z axis position binranges=[0:0.30,0.30:0.50,0.50:0.60]; [bincounts,ind]=histc(y1,binranges); bar(binranges,bincounts,0.8,'histc'); hold on; [bincounts,ind]=histc(y2,binranges); bar(binranges,bincounts,0.8,'histc'); hold on; [bincounts,ind]=histc(y3,binranges); bar(binranges,bincounts,0.8,'histc'); xlabel('Position (cm)','FontSize',20); ylabel('Number of people','FontSize',20); title('Pass Rate Report for IMRT Verification','FontSize',20); set(gca,'FontSize',20);
Attached is the file for the data
  1 件のコメント
Mostafa
Mostafa 2016 年 10 月 27 日
I think this is the same question as this one: Problem with loop to construct graph Please check to see if the answer provided satisfies your inquiry.
Also, it's good practice to bump old questions instead of asking new ones, since it increases the total number of views/reach and avoids redundancy. Cheers.

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

回答 (1 件)

Thorsten
Thorsten 2016 年 10 月 26 日
A=xlsread(filename);
for i = 1:3, h = histogram(A(:,i+1), [0 0.3 0.5 Inf]); hi(i,:) = h.Values; end
bar(hi)
legend({'0:0.3', '0.3:0.5', '0.3:1'})
  2 件のコメント
Nada Zamri
Nada Zamri 2016 年 10 月 26 日
thank you for your reply, i tried to use the command but it doesnt work. it said that Undefined function 'histogram' for input arguments of type 'double'. anyway I am using Matlab R2013a version.
Thorsten
Thorsten 2016 年 10 月 26 日
編集済み: Thorsten 2016 年 10 月 26 日
Then you can use
for i = 1:3, hi(i,:) = histcounts(A(:,i+1), [0 0.3 0.5 Inf]); end

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

カテゴリ

Help Center および File ExchangeBar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by