So right now I am using cellfun(@plot,My_cell) to plot a function from each column vector element in the cell. I would like to have each function plot to be labeled or named within the legend based on the elements in the array m = [1:4], for the four elements in the cell. How can I do this?

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 6 Aug. 2015

0 Stimmen

figure;
hold on
a={1:10 sin(1:10) cos(1:10)}
cellfun(@plot,a)
leg={'fig1' 'fig2' 'fig3'}
legend(leg)

Weitere Antworten (1)

the cyclist
the cyclist am 6 Aug. 2015

0 Stimmen

Using
cellfun(@plot,My_cell)
is a very clever way to plot the contents of each cell, but seems a bit precious to me (and I doubt has any upside besides the cleverness).
I think I would just use a for loop:
for nc = 1:numel(My_cell)
plot(My_cell{nc})
legend(...) % Whatever you wanted to do
end

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by