Borrar filtros
Borrar filtros

Legend in plot with a loop

1 visualización (últimos 30 días)
Hassan Bhatti
Hassan Bhatti el 22 de Feb. de 2019
Comentada: Rakhi Agarwal el 22 de Feb. de 2019
Hi,
I have some data which plots 48 different figures for 48 different points. I want to have some kind of loop which can be used in the Legend command for the plotting so that I don't have to write the Legend for the figures. I have the 48 points in a variable =a in the workspace.
for j=1:48
figure;
normB48points=(normB(:,j));
plot(t',normB48points);
xlabel('time in seconds (t)');
ylabel('flux densities in Tesla (T)');
legend('flux densities at point');
end

Respuesta aceptada

Rakhi Agarwal
Rakhi Agarwal el 22 de Feb. de 2019
Try this:
for j=1:48
figure;
normB48points=(normB(:,j));
plot(t',normB48points);
xlabel('time in seconds (t)');
ylabel('flux densities in Tesla (T)');
name = ['Flux densities at ', num2str(j)];
legend(name);
end
  2 comentarios
Hassan Bhatti
Hassan Bhatti el 22 de Feb. de 2019
Thank you for the answer.
It gives numbers as 1 to 48 as in the figure ans attached to this reply. But, I want to have these co-ordinates in figure coord attached.
Rakhi Agarwal
Rakhi Agarwal el 22 de Feb. de 2019
Then just modify the above code as follows:
Instead of:
name = ['Flux densities at ', num2str(j)];
Use:
name = ['Flux densities at ', num2str(a(1,j),',', num2str(a(2,j)];
where a is your coordinate vector.

Iniciar sesión para comentar.

Más respuestas (1)

Hassan Bhatti
Hassan Bhatti el 22 de Feb. de 2019
my matlab code and workspace is attached. It is still not working.
PFA
  4 comentarios
Hassan Bhatti
Hassan Bhatti el 22 de Feb. de 2019
Hey,
I thought it will be yours as your comment was in my thread. :D I accepted your first answer. Have a great day!
Rakhi Agarwal
Rakhi Agarwal el 22 de Feb. de 2019
Thanks! :D

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by