Trying to Plot cell array data

4 次查看(过去 30 天)
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 个评论
Adam Danz
Adam Danz 2020-10-31
编辑:Adam Danz 2020-10-31
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 2020-10-31
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.

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2020-10-31
编辑:Adam Danz 2020-10-31
"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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by