How can I plot a legend only for data points?

3 visualizaciones (últimos 30 días)
Rytis Stockus
Rytis Stockus el 8 de Oct. de 2018
Comentada: jonas el 9 de Oct. de 2018
Hello I try to plot a legend for different data points and get this error:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in Robertson86 (line 57) h(i)=plot(xdata(in),ydata(in),'o','Color',cdata2(i,:)); But it does work with line plots and fills.
for i = 1:12
% plot a polygon
Poly = Robertson_zones_1986{i};
plot(Poly(:,1),Poly(:,2),'k','LineWidth',1.5)
fill(Poly(:,1),Poly(:,2),cdata(i,:))
text(RobNumPos86(i,1),RobNumPos86(i,2),num2str(i),'Color',[0.3 0.3 0.3])
% check if data is inside this particular polygon
in= inpolygon(xdata,ydata,Poly(:,1),Poly(:,2));
h(i)=plot(xdata(in),ydata(in),'o','Color',cdata2(i,:));
b(i)=numel(xdata(in));
end
legend(h,'1.Data type','2.Data type',....)

Respuesta aceptada

jonas
jonas el 8 de Oct. de 2018
Your plot outputs multiple line handles. If that is not what you want, then you need to adjust the dimensions of xdata and ydata. If you want to plot multiple line objects in every iteration, then I suggest you store those values in a cell array:
h{i}=plot(xdata(in),ydata(in),'o','Color',cdata2(i,:));
  11 comentarios
Rytis Stockus
Rytis Stockus el 9 de Oct. de 2018
Yes, your solution does work as I wished. Thanks again for your help!
jonas
jonas el 9 de Oct. de 2018
Cheers!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Legend en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by