Use Legend to show array and matrix
Mostrar comentarios más antiguos
I have one array and one matrix like A={'x' 'y' 'z'}; B=[1 2 3]. I want to make a legend as: x=1 y=2 z=3
in my plot, could anyone help me with this issue.
Thanks
Respuesta aceptada
Más respuestas (1)
Honglei Chen
el 16 de Dic. de 2013
You can do this:
plot(rand(10,3))
legend(cellfun(@(x,y)sprintf('%s=%s',x,y),A,B,'UniformOutput',false))
8 comentarios
Wei
el 16 de Dic. de 2013
Azzi Abdelmalek
el 16 de Dic. de 2013
Why have you changed your question?
Wei
el 16 de Dic. de 2013
Honglei Chen
el 16 de Dic. de 2013
Your B now contains numbers, replace the second %s in my code to %d if they are integers
Wei
el 16 de Dic. de 2013
Honglei Chen
el 17 de Dic. de 2013
You change the second one to a regular array, you can use Walter's code below
Wei
el 17 de Dic. de 2013
Wei
el 17 de Dic. de 2013
Categorías
Más información sobre Legend en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!