How to plot my grafik in a gui axes ?

조회 수: 1 (최근 30일)
Zakaria Souf
Zakaria Souf 2018년 5월 13일
댓글: Zakaria Souf 2018년 5월 13일
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

답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by