How to plot my grafik in a gui axes ?

1 visualización (últimos 30 días)
Zakaria Souf
Zakaria Souf el 13 de Mayo de 2018
Comentada: Zakaria Souf el 13 de Mayo de 2018
Hi, I wrote a script that plots a map from some given ways and nodes structs data (my plot works fine), then I tried to plot this thing in a GUI Axes, first by copying my code and pasting it under the pushbutton function in the Matlab GUI function and then I tried some other stuff but nothing has worked.
this is my code that plots fine but how to plot it in a GUI Axes ???:
%plot ways
for i=1:1:length(ways)
value = getfield(ways(i), 'latLon');% acces field
plot(value(:,2),value(:,1));
set(gca,'color',[0.8 0.8 0.8])% color the backround
hold on
end
%plot nodes
for i=1:1:length(nodes)
value1 = getfield(nodes(i), 'latLon');
plot(value1(:,2),value1(:,1),'o')
end
%plot within this x and y boundries
xlim([bounds.minLon bounds.maxLon]);
ylim([bounds.minLat bounds.maxLat]);
%begin the filling and drwing process
for i=1:1:length(ways)
mytags = getfield(ways(i), 'tags'); %get all of my tags
mykeys = keys(mytags); % get all of my tags keys
myvalues = values(mytags); % get all of my tags values
%fill buildings
bu= find(contains(mykeys,'building')); % find the word building in mykeys
if ~isempty(bu) %if the word exist( buil is not empty)
vn=getfield(ways(i), 'latLon');
fill(vn(:,2),vn(:,1),[0.8 0.6 0.2]); % fill my building
end
end

Respuestas (1)

Jan
Jan el 13 de Mayo de 2018
Do not use gca to obtain the handle of an axes, but specify the handles of an existing axes object:
plot(value(:,2),value(:,1));
set(gca,'color',[0.8 0.8 0.8])%
==>
ax = handles.axes1;
plot(ax, value(:,2),value(:,1));
set(ax,'color',[0.8 0.8 0.8])
Specify the axes in the other commands also:
xlim(ax, [bounds.minLon bounds.maxLon]);
ylim(ax, [bounds.minLat bounds.maxLat]);
fill(ax, vn(:,2),vn(:,1),[0.8 0.6 0.2]);
By the way, getfield is not convenient. Compare:
vn = getfield(ways(i), 'latLon');
vn = ways(i).latLon;
  1 comentario
Zakaria Souf
Zakaria Souf el 13 de Mayo de 2018
thank you for the answer but now I am getting this error: Undefined variable "handles" or class "handles.axes1".

Iniciar sesión para comentar.

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by