Plotting cell of different sized vectors

Hi guys,
I have a cell such that:
The cell index (1,2,3...) corresponds to a timeline.
Each cell element holds a vector (of different sizes) with several values indicating dominant frequencies at that time.
I wish to plot a graph in which the x axis is the timeline (the cells' indexes), and for each "time" to display dots showing all dominant frequencies of that time.
The problem is that there is a different number of "dominant frequencies" for each time.
I also want to plot the dots for each time in different colors specifying how strong the corresponding frequency is at that time.
Is there any way to do this?
Thanks!

답변 (1개)

Adam Danz
Adam Danz 2019년 12월 2일
편집: Adam Danz 2019년 12월 3일

1 개 추천

You could use arrayfun()
Here's a demo. C is the cell array containing vectors, h is the handles to each line object.
C = {[2 4 6 8 10], [6 5 4], [0 1], 10:20};
axes()
hold on
h = arrayfun(@(i)plot(C{i},'o'),1:numel(C));
grid on
[Update] following comments below that clarified the problem.
C is the cell array containing the y-values. h is the handles to each line object.
C = {(1), [1 2] [1 2 3 4 5] };
clf()
axes()
hold on % important to hold axes prior to plotting
h = arrayfun(@(i)plot(i,C{i},'o'),1:numel(C));
Note, if C has any empties, you'll either need to replace the empties with NaN or remove them prior to plotting.
C = {(1), [1 2] [ ] [1 2 3 4 5] };
C(cellfun(@isempty,C)) = {nan}; %This preserves the x-index value
C(cellfun(@isempty,C)) = []; %This does not

댓글 수: 2

Hanna Weiss
Hanna Weiss 2019년 12월 3일
Hey :)
Thanks for the answer!
I did not explain well - I do not want all vectors to correspond to the same timeline.
I want for every "time" (as in every x-axis index) to plot the corresponding vector vertically.
Say I have the cell: { [1] [1 2] [1 2 3 4 5] }
Then I want at x=1 to plot a dot at y=1,
and at x=2 to plot 2 dots at y=1,2
and at x=3 to plot 5 dots at y=1,2,3,4,5...
is there any way to do this?
Thanks!!
Adam Danz
Adam Danz 2019년 12월 3일
편집: Adam Danz 2019년 12월 4일
Sure, see updated answer. Again, using arrayfun.

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

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2019년 12월 2일

편집:

2019년 12월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by