Trying to Plot cell array data

2 views (last 30 days)
Mohamed Eltaeb
Mohamed Eltaeb on 30 Oct 2020
Edited: Adam Danz on 31 Oct 2020
So I have a dataset of music data that I am trying to correlate with information collected on the y axis. The data itself is a cell array containing a 2 element list in each index of the cell array, like this below.
1 2 3
[0.5,0.8] [1.3,2.4] [3.7, 6.1]
I want to plot this data as the x-axis against the information collected on the y axis, where between the two numbers in each list, it correlates to the value on the y-axis. This would look similar to a rectangular waveform.
Thanks
Mo
  2 Comments
Adam Danz
Adam Danz on 31 Oct 2020
Edited: Adam Danz on 31 Oct 2020
You lost me here:
I want to plot this data as the x-axis against the information collected on the y axis, where between the two numbers in each list, it correlates to the value on the y-axis.
I'm assuming the cell array is,
c = { [0.5,0.8], [1.3,2.4], [3.7, 6.1] };
Do you mean those are the x-coordinates?
What are the y coordinates?
What do you mean "Between the two numbers?
Correlation of what?
Mohamed Eltaeb
Mohamed Eltaeb on 31 Oct 2020
Yes the cell array is oriented like you displayed. the two numbers in each list are a range of x coordinate values, so from 0.5 to 0.8, they have the same y value.
What I am trying to do is create a sort of bar graph that has the left most point of the bar start at first value (0.5) in the list and the right most point of the bar end on the second value in the list of the cell array (0.8) and have their y value in that range be equal to 1 y-value which is why itd look like a bar.
I hope that explains it better. Thanks for the help in advance.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 31 Oct 2020
Edited: Adam Danz on 31 Oct 2020
"What I am trying to do is create a sort of bar graph that has the left most point of the bar start at first value (0.5) in the list and the right most point of the bar end on the second value in the list of the cell array (0.8) and have their y value in that range be equal to 1 y-value which is why itd look like a bar. "
Bar plots have uniform widths but your bar widths aren't uniform so you cannot use bar().
Histograms can have different widths.
% c is a cell array of 1x2 vectors.
c = { [0.5,0.8], [1.3,2.4], [3.7, 6.1] };
% y is a cell array the same size as c containing scalar values
y = {2,3,4};
% Create plot
cla()
hold on % important
cellfun(@(edges,count)histogram('BinEdges',edges,'BinCounts',count),c,y)
  3 Comments
Adam Danz
Adam Danz on 31 Oct 2020
Edited: Adam Danz on 31 Oct 2020
Glad I could help!

Sign in to comment.

More Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!