To transfer datas among the GUIs

Hello every one; I have created a main UI having a popup menu that contains circle,Rectangle and Triangle.If user will clicks circle (then another ui will open,there user will enter the value of radius and this value will transfer to main ui) elseif user will click rectangle (then rectangle ui will open,there user will enter the value of length and breadth, and these values will come to the main ui) else if user will click Triangle (then triangle ui will open there user will enter the value of length and height, and these values will return to main ui),after this area and perimeter will be calculated and result will be displayed in main ui. I have written the following code for this but i am getting error message please any
name =get(handles.geo,Value) % geo is the tag of popup menu geometry(circle,rectangle,triangle)
if name==1
cirlce;% open first UI(circle)
elseif name==2
rectangle;%Open secnd UI(Rectangle)
elseif name==3
triangle;%Open third UI(Triangle)
end
if name==1
r=getappdata(0,Variable1) % get the value of radius from circle UI
area=pi*r*r;
perm=2*pt*r;
elseif name==2
data=getappdata(0,variable2)% get the value of length and breadth from rectangle
l=data(1);% length of rectangle first value of data
b=data(2);% breadth of rectangle second value of data
area=l*b;
perm=2*(l*b);
elseif name==3
% same like previous
end
% send the values to edit text area and perm in main UI.
But while running the code main UI is opening, after clicking popup menu (for example 1 i.e. circle) circle UI is opening and an error message is coming r=[]. it is not calculating area and perimeter. any one please suggest how to do it. sryfor bad english.Thanks in advance...

1 Comment

It looks like you misspelled circle as "cirlce" Make sure your spelling is consistent and correct.
If that's not the problem, then post your error message. That means ALL the red text , not just part of it.

Sign in to comment.

 Accepted Answer

You probably want
r=getappdata(0,'Variable1') % get the value of radius from circle UI
as the second parameter to getappdata is a string.

9 Comments

Debashis Panda
Debashis Panda on 29 Dec 2016
Edited: Debashis Panda on 29 Dec 2016
Thank you very much Walter for your quick replay. But i have already used setappdata and getappdata to transfer the values between popup menu UIs(circle UI,rectangle UI, triangle UI) and main UI . But when main UI is running i am clicking circle in popup menu then circle UI is opening and at the same time main UI is displaying r=[] in command window. I want option like after clicking main UI circle UI will open there i will enter my vallues, then these values will come to main UI, and main UI will be executed by using the vallues that provided in circle UI for further calculation. thank u once again...
To prevent
r=[]
from showing, change
r=getappdata(0,Variable1)
to
r=getappdata(0,Variable1);
Dear walter thanks again once more for your quick replay, but r=[] showing means the value of r is not transferring from circle UI to main UI in setappdata and getappdata, As i have mentioned before the second part (loops for calculation) executes. so in all future calculation related to r (area and perimeter) is showing (area=[], perimeter=[]).
Also in my case, the calculation is based on geometry (circle,rectangle,triangle).If circle will be clicked then radius value will be entered in another UI (circle),then the value will returned to first UI(also, if circle UI will clicked then area will be calculetd as=pi*r*r,perimeter=2*pi*r, if rectangle will be clicked then area will be calculated as l*b(the values of l and b will be entered in rectangle UI),like wise for triangle). So in main UI it will be written like this after circle UI will open,the main programme will not go to next line until the value came from circle UI.
Walter Roberson
Walter Roberson on 29 Dec 2016
Edited: Walter Roberson on 29 Dec 2016
"r=[] showing means the value of r is not transferring from circle UI to main UI in setappdata and getappdata"
Your code in the circle UI must be wrong.
There is not much more we can say without access to the circle code; and preferably to the actual source code to all of the routines.
Dear sir thanks,here i have attached the code
% this is code of main UI
geom1 = get(handles.geom,'Value'); 5geom is the gag of popupmenu that accepts geometry(1 mean circle,2 rectangle,3 triangle)
if geom1==1
circle1; % open circle1 UI
elseif geom1==2
rectangle1; % open rectangle1 UI
elseif geom1==3
triangle1; 5 open triangle UI
end
% this part will calculate the area and perimeter of the geometry selected the the popup-menu after getting the values from corresponding UI
if geom1==1
r=getappdata(0, 'variable1'); % get the value of radius from radius UI
area=pi*r*r;% calculate area of circle
perm=2*pi*r; % calculate perimeter of circle
elseif geom1==2
data=getappdata(0, 'variable2'); % get the values of length and breadth from rectangle UI
l=data(1); % length
b=data(2); % breadth
area=l*b; % calculate area of rectangle
perm=2*(l+b); % calculate perm of rectangle
elseif geom1==3
data1=getappdata(0, 'variable2'); % gets datas from triangle1 UI
b=data1(1)
h=data1(2)
% area and perimeter
end
set(handles.edit1,'string',num2str(area)); % set the value of area to UI (displayed in main UI)
set(handles.edit2,'string',num2str(perm)); % set the value of area to UI (displayed in main UI)
code of circle1 UI
%This code written under OK button that transfer the values from circle1 UI to main UI
% ok button of circle UI
radius = str2num(get(handles.edit1,'String')); % edit 1 is the tag of radius
setappdata(0, 'variable1',radius);
close circle1; % close circle1 UI
the code written under rectangle1 UI
length = str2num(get(handles.edit1,'String')); % edit 1 is the tag of length in rectangle1 UI
breadth=str2num(get(handles.edit2,'String')); % edit 2 is the tag of breadth in rectangle1 UI
data=[length;breadth] % both are converted into a matrix form
setappdata(0, 'variable2',data);
close ractangle1;
like wise code is written for other UI
Thank u sir once again.....
Does your code for circle uiwait() or waitfor() to prevent the main routine from continuing until the data is entered? It needs to wait for the input. Or you could code the call as
uiwait(circle1())
Debashis Panda
Debashis Panda on 31 Dec 2016
Edited: Debashis Panda on 31 Dec 2016
Thnak you sir, it is the correct answer wish you a happy new year.....

Sign in to comment.

More Answers (1)

adi kul
adi kul on 29 Dec 2016
Edited: adi kul on 29 Dec 2016
try using
setappdata
instead! Getappdata returns values while setappdata stores it. More information:

1 Comment

Dear adi, thanks for your quick replay but i have already used setappdata (in UI circle,rectangle and triangle) to transfer the values to main UI. But before the values are returned to main UI, it is displaying error message (r=[] , data=[], l=[],b=[]).

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Products

Tags

Community Treasure Hunt

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

Start Hunting!