Plotting cell of different sized vectors
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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!
0 comentarios
Respuestas (1)
Adam Danz
el 2 de Dic. de 2019
Editada: Adam Danz
el 3 de Dic. de 2019
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 comentarios
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!