MATLAB: I want to create an interface in which I present the figure

boutonfigure

I want to create an interface in which I present my figure (wsn) and a button 'on' that make a well determine (calculate distance and make a line if d <30) spot but I not succeed which can help me to correct this code,thks.
function varargout = aze(varargin)
Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @aze_OpeningFcn, ...
'gui_OutputFcn', @aze_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% Simple WSN Animator
%cree des point(o1,o2)calculer la distance d et teste s'il est inferieur a30

clear all;
close all;
clc;
%%creation of nodes

% Total Numbr of Nodes

Totalnodes='10';
%N11=10 Totalnodes(((((converts the string of a numeric value)))

n11=str2num(Totalnodes);
%%distance of nodes

min=20;
max=120;
% MATRICE o1,o2

o1 = floor(min + (max-min).*rand(1,n11))
o2 = floor(min + (max-min).*rand(1,n11))
plot(o1,o2,'^','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','y',...
'MarkerSize',12);
for i=1:100%coverage range

for j=1:n11
text(o1(j),o2(j),int2str(j),'FontSize',12);
end
end
% --- Executes just before aze is made visible.
function aze_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB


% handles structure with handles and user data (see GUIDATA)


% varargin command line arguments to aze (see VARARGIN)
set(hObject,'toolbar','figure') ;
% Choose default command line output for aze
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes aze wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = aze_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;
% --- Executes on button press in on_pushbutton1.
function on_pushbutton1_Callback(hObject, eventdata, handles)
Simple WSN Animator
%cree des point(o1,o2)calculer la distance d et teste s'il est inferieur a30
%
clear all;
close all;
clc;
%%creation of nodes
% Total Numbr of Nodes
Totalnodes='10';
%N11=10 Totalnodes(((((converts the string of a numeric value)))
n11=str2num(Totalnodes);
%%distance of nodes
min=20;
max=120;
% MATRICE o1,o2
o1 = floor(min + (max-min).*rand(1,n11))
o2 = floor(min + (max-min).*rand(1,n11))
plot(o1,o2,'^','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','y',...
'MarkerSize',12);
%CALCULE LA DISRANCE d
d = zeros(n11,n11);
for i=1:n11
for j=i+1:n11
d(i,j) = sqrt((o1(i)-o1(j))^2 + (o2(i)-o2(j))^2);
d(j,i) = d(i,j)
end
end
% POUR COMPARE LE d ET LINE
for i=1:n11
for j=i+1:n11
if d(i,j)<=30
line([o1(i) o1(j)],[o2(i) o2(j)]); % supply both the x and y components
end
end
end
for i=1:100%coverage range
for j=1:n11
text(o1(j),o2(j),int2str(j),'FontSize',12);
end
end
% hObject handle to on_pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

Best Answer

You need to remove the "clear all" and "close all". Those are cargo cult programming
Related Question