Problem with loop to construct graph

조회 수: 1 (최근 30일)
Nada Zamri
Nada Zamri 2016년 10월 26일
편집: Mostafa 2016년 10월 27일
Currently I am working on constructing a bar graph for my data (file as attached). But I encountered some problem while trying to rearrange the the data into specific categories. I would like to plot one figure for each position, which means
for Figure 1 ( x position), there will be 3 categories a) x <0.3 cm b) 0.3 cm<x<0.5 cm c) x >0.5 cm
and classify all the data in the column max-x (excel file as attached, sheet name : Book1) into these 3 categories. I already tried using hist and binranges command but it does not work.
  댓글 수: 2
Mostafa
Mostafa 2016년 10월 26일
편집: Mostafa 2016년 10월 26일
Can you please clarify what you want to do exactly? Do you want to draw a bar chart for the number of points according to the given criteria? For example something like this:
|
|
| |
  | |
  x<0.3   0.3<x<0.5   x>0.5
Or what exactly?
Nada Zamri
Nada Zamri 2016년 10월 26일
yes exactly like that.

댓글을 달려면 로그인하십시오.

채택된 답변

Mostafa
Mostafa 2016년 10월 27일
편집: Mostafa 2016년 10월 27일
%Reading the data from sheet 1, cells B2 to D8
dataMat = xlsread('Book1.xlsx', 1, 'B2:D8', 'basic');
%Get sum of numbers that satisfy the conditions for x-column
x1 = sum(dataMat(:, 1) < 0.3);
x2 = sum((dataMat(:, 1) > 0.3) & (dataMat(:, 1) < 0.5));
x3 = sum(dataMat(:, 1) > 0.5);
%Draw, bar width = 0.5 for readability
bar([x1 x2 x3], 0.5);
%Rename x-axis to be more meaningful
set(gca,'XTickLabel',{'x < 0.3', '0.3 < x < 0.5', 'x > 0.5'});

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by