From: James on
Hello ladies and gentlemen. I'm having an issue with plotting my data on the axes in my GUI. First of all let me explain what I'm trying to do. Basically I'm working on my final project at school and I have written code for the program to work, and it does, but now I'm attempting to incorporate the functions and such into a GUI but I'm having trouble with the plotting. Below is the code that I am using to run the program with our the gui.

---------------------------------------------------------------------------------------
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
% Create the Plot in Opening Function
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

figureHandle = figure('NumberTitle','off',...
'Name','Location of Target',...
'Color',[0 0 1],'Visible','off');


% Set axes
axesHandle = axes('Parent',figureHandle,...
'YGrid','on',...
'YColor',[0.9725 0.9725 0.9725],...
'XGrid','on',...
'XColor',[0.9725 0.9725 0.9725],...
'Color',[0 0 0]);

hold on;

plotHandle = plot(axesHandle,xz,yz,'Marker','*','LineWidth',2.0,'Color',[0 1 0]);

ylim(axesHandle,[min(0) max(50)]);
xlim(axesHandle,[min(0) max(50)]);

% Create xlabel
xlabel('Distance in ft.','FontWeight','bold','FontSize',14,'Color',[1 1 0]);

% Create ylabel
ylabel('Distance in ft.','FontWeight','bold','FontSize',14,'Color',[1 1 0]);

% Create title
title('Location of Target','FontSize',15,'Color',[1 1 0]);




%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
% Connect to the Serial ports
% (Make this a Button)
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

RecA = serial('COM4');
RecB = serial('COM5');
RecC = serial('COM5');
RecD = serial('COM5');

%Set connection properties
RecA.Baudrate = 9600;
RecB.Baudrate = 9600;
RecC.Baudrate = 9600;
RecD.Baudrate = 9600;

RecA.InputBufferSize = 7;
RecB.InputBufferSize = 7;
RecC.InputBufferSize = 7;
RecD.InputBufferSize = 7;

set(RecA, 'Terminator', '');
set(RecB, 'Terminator', '');
set(RecC, 'Terminator', '');
set(RecD, 'Terminator', '');

fopen(RecA);
fopen(RecB);
fopen(RecC);
fopen(RecD);





%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
% Collect the RSSI values, Convert to Distance,Run Algo, Plot Result
% (Make this a Button)
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

%% Set the time span and interval for data collection
stopTime = '03/10 21:53';
timeInterval = 0.1;

%% Collect data
count = 1;

while ~isequal(datestr(now,'mm/DD HH:MM'),stopTime)
B=fgetl(RecA);
C=fgetl(RecB);
D=fgetl(RecB);
E=fgetl(RecB);

RSSI1(count) = sscanf(B, ['1' 'g' 'c' 'G' '%d'])
RSSI2(count) = sscanf(C, ['1' 'g' 'c' 'G' '%d'])
RSSI3(count) = sscanf(D, ['1' 'g' 'c' 'G' '%d'])
RSSI4(count) = sscanf(E, ['1' 'g' 'c' 'G' '%d'])


% Convert to Distance

t = 70:1:99;
p = [28 27 26 25 24 ...
23 22 21 20 19 ...
18 17 16 15 14 ...
13 12 11 10 9 ...
8 7 6 5 4 ...
3 2 1 0.5 0];

d1 = interp1(t,p,RSSI1(count))
d2 = interp1(t,p,RSSI2(count))
d3 = interp1(t,p,RSSI3(count))
d4 = interp1(t,p,RSSI4(count))



% Trilateration Algorithm

l=[d1;d2;d3;d4];


% Receiver Locations

xa=20;
ya=20;

xb=20;
yb=25;

xc=25;
yc=25;

xd=25;
yd=20;

xz=1;
yz=1;


B=zeros(4,2);
f=zeros(4,1);

max_iter=10;
iter1=1;
keep_going=1;

% convergence variables
phi=10;
last_phi=20;
threshold=1.0e-06;

%for i=(1:1:prev1)
while keep_going == 1
d_af=sqrt((xa-xz)^2 + (ya-yz)^2);
d_bf=sqrt((xb-xz)^2 + (yb-yz)^2);
d_cf=sqrt((xc-xz)^2 + (yc-yz)^2);
d_df=sqrt((xd-xz)^2 + (yd-yz)^2);


% make coefficients of the condition equations

B(1,:)=[(xa-xz)/d_af (ya-yz)/d_af];
B(2,:)=[(xb-xz)/d_bf (yb-yz)/d_bf];
B(3,:)=[(xc-xz)/d_cf (yc-yz)/d_cf];
B(4,:)=[(xd-xz)/d_df (yd-yz)/d_df];


f(1)=-(d1 - sqrt((xa-xz)^2 + (ya-yz)^2));
f(2)=-(d2 - sqrt((xb-xz)^2 + (yb-yz)^2));
f(3)=-(d3 - sqrt((xc-xz)^2 + (yc-yz)^2));
f(4)=-(d4 - sqrt((xd-xz)^2 + (yd-yz)^2));


if iter1 == 1
disp('iteration 1 B,f,W');
B;
f;
end

% now solve and update and check convergence

N=B'*B;
N;
t=B'*f;
t;
iter1
del=inv(N)*t;
del;

xz=xz + del(1);
yz=yz + del(2);
v=f-B*del;
v;
phi=v'*v;


if( abs(phi-last_phi)/last_phi < threshold )
keep_going=0;

disp('Converged');
end
last_phi=phi;
if iter1 > 10
keep_going=0;
disp('No solution');
end
iter1=iter1+1;

end
disp('final coordinates');
[xz yz]

% Plot the Final Coordinates

set(plotHandle,'YData',yz,'XData',xz);
set(figureHandle,'Visible','on');

pause(timeInterval);
count = count +1;
end

%% Put the instrument in local mode
fprintf(RecA,'SYSTEM:LOCAL');
fprintf(RecB,'SYSTEM:LOCAL');
fprintf(RecC,'SYSTEM:LOCAL');
fprintf(RecD,'SYSTEM:LOCAL');

%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
% Close Ports
% (Make this a Button)
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
fclose(RecA);
fclose(RecB);
fclose(RecC);
fclose(RecD);

delete(RecA);
delete(RecB);
delete(RecC);
delete(RecD);

clear RecA;
clear RecB;
clear RecC;
clear RecD;

--------------------------------------------------------------------------------------------------

Ok so basically I want the exact figure layout that is created in the beginning of the code, however I want it to be in my gui. When I try to place it in the figure_createFcn or in the opening_Fcn nothing happens. The most I've been able to get it to open a separate figure and plot on that.I have attempted to use the handles but no luck. I've already incorporated the rest of the info in the gui and added a lot more, but I'm having trouble with this part. I can include the m file of the gui as well if need be, but I didn't want to post it here because it is very long. My axes name is figure. Please if anyone has any hints or suggestions please let me know. In case anyone is wondering I am using active RFID as a means of tracking an individual in an indoor environment. Thanks in advance and sorry for the lengthy first post.
From: James on
Well this forum moves very fast. Bumping this thread so that someone will see it. Thanks
From: ImageAnalyst on
James:
It helps if you make it easy for us. For example, I simply copied and
pasted your code and I got an error:
??? Undefined function or variable 'xz'.

Error in ==> test1 at 19
plotHandle = plot(axesHandle,xz,yz,'Marker','*','LineWidth',
2.0,'Color',[0 1 0]);

that is apparently not related to what you're asking, but I'm not sure
because all you said is that it doesn't work. So basically I quit at
that point. Maybe you've tried to change the code so we can try it
but it didn't work because you didn't supply us with any data for xz.

It appears that you're using GUIDE so why don't you just put an axes
on the figure and use handles.axesPlot or something similar to refer
to it, rather than try to create a brand new axes in the opening Fcn?
From: James on
My apologies for the error. I was messing with the program a little and I forgot to put xz and yz back into the mix. I initially set both xz=0 and yz=0. Placing this into the code it should look like this

----------------------------------------------------------------------
xz=0;
yz=0;

figureHandle = figure('NumberTitle','off',...
'Name','Location of Target',...
'Color',[0 0 1],'Visible','off');


% Set axes
axesHandle = axes('Parent',figureHandle,...
'YGrid','on',...
'YColor',[0.9725 0.9725 0.9725],...
'XGrid','on',...
'XColor',[0.9725 0.9725 0.9725],...
'Color',[0 0 0]);

hold on;

plotHandle = plot(axesHandle,xz,yz,'Marker','*','LineWidth',2.0,'Color',[0 1 0]);

ylim(axesHandle,[min(0) max(50)]);
xlim(axesHandle,[min(0) max(50)]);

% Create xlabel
xlabel('Distance in ft.','FontWeight','bold','FontSize',14,'Color',[1 1 0]);

% Create ylabel
ylabel('Distance in ft.','FontWeight','bold','FontSize',14,'Color',[1 1 0]);

% Create title
title('Location of Target','FontSize',15,'Color',[1 1 0]);
---------------------------------------------------------------------------------------------------
You are correct in your assumption that I am using the guide. I've attempted to use the property inspector for the axes, but I haven't been able to achieve the same results in terms of the colors and axis titles, or to have anything plot on the actual axes in my gui. That's why I was wanting to put this into the opening function because this is exactly how I want my figure to look. If there is another way of doing it such as using the handles please let me know. I have only been using matlab for approx. 1.5 months so any advice will help and be appreciated.
From: ImageAnalyst on
James:
You might want to take a look at this GUIDE template:
http://www.mathworks.com/matlabcentral/fileexchange/24224

You can place an axes on there in GUIDE with some rough appearance,
and then do finer tweaks in the code if you wish. In that case, you
wouldn't the axes command to create a NEW axes, you'd just use your
existing axes (with its existing tag, e.g. handles.axesPlot) and then
tweak its settings with the set() function, e.g.:

set(handles.axesPlot, 'XGrid', 'on');

or whatever...

I often have two on my GUIs, handles.axesPlot, and handles.axesImage,
and sometimes handles.axesHistogram.

 |  Next  |  Last
Pages: 1 2 3
Prev: problem with dicomwrite
Next: integrate and fire model