Plot is making marker at origin

In my gui code for plotting resultant vectors from gravity, when I plot the circles to represent point masses, I'm getting a marker at the origin. I don't know why it shows a marker, but it only seems to do it whenever one point is far enough away from the origin to move the boundary of the graph.
%get user data from gui
plot(x1,y1,'.','markersize',60)
hold on
plot(x2,y2,'.r','markersize',60)
hold off
The problem occurs in the plot, where a 3rd marker is appearing with the characteristics of the last marker created at the origin. How can I remove this 3rd marker from the plot as it is not needed?

 採用された回答

Geoff Hayes
Geoff Hayes 2014 年 12 月 7 日

0 投票

Jared - are x1, y1, x2, y2 scalars or vectors? If they are vectors, then you could very well be replacing the original point, (x1,y1), with the marker depending upon how you are creating x2 and y2. For example,
figure;
x1 = 10;
y1 = 10;
x2 = [x1 50];
y2 = [y1 50];
plot(x1,y1,'.','markersize',60)
hold on
The above call to plot creates a blue dot at the centre ("origin") of the figure. And once we call
plot(x2,y2,'.r','markersize',60)
hold off
because x2 and y2 include the origin of (x1,x2), the original blue dot is replaced with the red marker. Is this what is happening?

3 件のコメント

Jared
Jared 2014 年 12 月 7 日
function calc_Callback(hObject, eventdata, handles)
% hObject handle to calc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%get user data from gui
cla(handles.plot,'reset')
hm1 = findobj('tag','Mone');
hm2 = findobj('tag','Mtwo');
hx1 = findobj('tag','xone');
hy1 = findobj('tag','yone');
hx2 = findobj('tag','xtwo');
hy2 = findobj('tag','ytwo');
m1 = str2double(get(hm1,'String'));
m2 = str2double(get(hm2,'String'));
x1 = str2double(get(hx1,'String'));
y1 = str2double(get(hy1,'String'));
x2 = str2double(get(hx2,'String'));
y2 = str2double(get(hy2,'String'));
%calculates data from points
r = hypot(x1-x2,y1-y2);
G = 6.674*10^(-11);
F = G .* m1 .* m2.\r.^2;
ar = 2;
mag = findobj('tag','magnitude');
set(mag,'string',num2str(F))
urx1 = (x2-x1).\r;
ury1 = (y2-y1).\r;
urx2 = (x1-x2).\r;
ury2 = (y1-y2).\r;
ax1 = ar .* urx1;
ay1 = ar .* ury1;
ax2 = ar .* urx2;
ay2 = ar .* ury2;
plot(x1,y1,'.','markersize',60)
hold on
plot(x2,y2,'.r','markersize',60)
set(gcf,'Units','normalized')
%[figx1, figy1] = dsxy2figxy(handles.plot,[x1,ax1],[y1,ay1]);
%[figx2, figy2] = dsxy2figxy(handles.plot,[x2,ax2],[y2,ay2]);
%annotation('textarrow',[figx1(1),figx1(2)],[figy1(1),figy1(2)],...
% 'String',F)
%annotation('textarrow',[figx2(1),figx2(2)],[figy2(1),figy2(2)],...
% 'String',F)
quiver(x1,y1,ax1,ay1,'MaxHeadSize',.8)
quiver(x2,y2,ax2,ay2,'MaxHeadSize',.8)
Thats my code for the whole function when calculate is pressed. I don't believe they are vectors (unless something in the code is making them so). Is there something in here that is setting the values as arrays
Jared
Jared 2014 年 12 月 7 日
So I unsilenced the x1 y1 x2 and y2 variables, theyre all vectors with values that was input and a zero in the next row. I believe this is due to them being called as doubles. How do I convert the string to just their numeric value?
Geoff Hayes
Geoff Hayes 2014 年 12 月 7 日
Jared - what happens if you just call
get(hx1,'String')
without the str2double? What do you observe?
As an aside, you shouldn't have to use findobj to get the handles to your widgets. Just use
m1 = str2double(get(handles.Mone,'String'));
instead of
hm1 = findobj('tag','Mone');
m1 = str2double(get(hm1,'String'));

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

質問済み:

2014 年 12 月 7 日

コメント済み:

2014 年 12 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by