How to plot my grafik in a gui axes ?

1 vue (au cours des 30 derniers jours)
Zakaria Souf
Zakaria Souf le 13 Mai 2018
Commenté : Zakaria Souf le 13 Mai 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

Réponses (1)

Jan
Jan le 13 Mai 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 commentaire
Zakaria Souf
Zakaria Souf le 13 Mai 2018
thank you for the answer but now I am getting this error: Undefined variable "handles" or class "handles.axes1".

Connectez-vous pour commenter.

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by