Plot into existing Gui figure/axes
6 次查看(过去 30 天)
显示 更早的评论
hello, i am new at matlab and need help at the following problem:
i created a gui axes and colleceted x and y coordinates from it.
now I want to plot a dot at (x,y) into the existing axes. Like a marker where i clicked.
thats my code right now:
% --- Outputs from this function are returned to the command line.
function varargout = feld6_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
title('sPiElFeLd');
global n % n input is in an other gui
set(gca,'XTick',(1:1:n));
set(gca,'YTick',(1:1:n));
xlim([0.5 n+0.5])
ylim([0.5 n+0.5])
% squares for field
for k= 0:1:n-1
for j=0:1:n-1
rectangle('Position', [k+0.5 j+0.5 1 1])
end
end
% Click positions
[x,y] = ginput(1);
x = int64(x); % x Click position
y = int64(y); % y Click position
4 个评论
Adam Danz
2019-11-21
The reason you got an error with solution 1 is because I totally made up the variable name "axisHandle". I could have named it "SantaClaus". That variable should be the axis handle to the axis you're plotting on. It needs to be replaced with your variable name. Here's an example.
ax = axes();
plot(ax, 0,0,'bo')
See the documentation for more info: plot(ax,___)
The second problem is probably because you're not holding the axis. Check out the docmentation: hold on
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!