why my output not display?

26 views (last 30 days)
nursuhailah suhaimi
nursuhailah suhaimi on 1 Nov 2016
Commented: Nick Counts on 6 Nov 2016
please help me. i want to seperate input(fillmodule.fig) and output(CUBA.fig)... but when run, CUBA.fig not show any value. i hope you can help me. thankyou
  2 Comments
Walter Roberson
Walter Roberson on 1 Nov 2016
Please attach the .m and the .fig file. It is difficult to read the code from the images.

Sign in to comment.

Answers (2)

Nick Counts
Nick Counts on 5 Nov 2016
Edited: Nick Counts on 5 Nov 2016
Walter is spot-on that the .m file is really needed for specific help. If I read your problem description correctly, you are trying to make one GUI interact with another.
You will need some way of getting data from one to the other. There are a few options.
  1. Passing the needed data as an argument
  2. Using setappdata and getappdata
  3. Using the handles to the uicontrols to populate between GUI figures (probably not the best idea).
Without knowing more about what you are trying to accomplish, and without the code, it's hard to go much further.
If the CUBA figure was generated by GUIDE, then it will pass you a handle.
Inside fillmodule:
hCubaGUI = CUBA_Function()
setappdata(hCubaGUI, 'roofLength', roofLengthVariable);
setappdata(hCubaGUI, 'roofWidth', roofWidthVariable);
setappdata(hCubaGUI, 'maxPower', maxPowerVariable); % Reminds me of Homer Simpson!
Inside CUBA
% make a structure containing all appdata
appDataStructure = getappdata(gcf);
% Or make a unique variable for each appdata
roofLength = getappdata(gcf, 'roofLength');
Check out
doc setappdata
doc getappdata
and you should be on a good path.
Good luck
  1 Comment
Nick Counts
Nick Counts on 5 Nov 2016
Ok, there's a lot going on here.
In fillmodule.m you tried to add setappdata to all the functions with names like ANumberofrooftop_CreateFcn
These functions are only executed at the time of figure construction. The place you want to add code is to the callback function for your pushbutton.
Try changing fillmodule.m so the NEXT_Callback function is this:
% --- Executes on button press in NEXT.
function NEXT_Callback(hObject, eventdata, handles)
hCubaGUI = CUBA();
setappdata(hCubaGUI, 'ALengthofrooftop', handles.ALengthofrooftop.String);
setappdata(hCubaGUI, 'ANumberofrooftop', handles.ANumberofrooftop.String);
setappdata(hCubaGUI, 'AWidthofrooftop', handles.AWidthofrooftop.String);
% You need to pass a value for Maximum power, and I am not sure where you
% are getting that value. So for this example, I will just pass the number
% 4, meaning 4 kW.
setappdata(hCubaGUI, 'Maximumpower', 4);
data = guihandles(hCubaGUI);
data.errorString = 'Total number of mistakes: ';
data.numberOfErrors = 0;
guidata(hCubaGUI, data);
and then change CUBA.m so the pushbutton1_Callback function is this:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
ALengthofrooftop = getappdata(gcf, 'ALengthofrooftop');
ANumberofrooftop = getappdata(gcf, 'ANumberofrooftop');
AWidthofrooftop = getappdata(gcf, 'AWidthofrooftop');
Maximumpower = getappdata(gcf, 'Maximumpower');
a = str2num(ANumberofrooftop);
b = str2num(ALengthofrooftop);
c = str2num(AWidthofrooftop);keyboard
d = Maximumpower;
x = ( b / (1.58 + 0.01) )
x = fix(x)
y = ( c / (0.812 + 0.01) )
y = fix(y)
z = x * y
z = fix(z)
xxx = num2str (x)
yyy = num2str (y)
zzz = num2str (z)
set(handles.AN1,'string',xxx)
set(handles.AN2,'string',yyy)
set(handles.AN3,'string',zzz)
o = ( b / (0.812 + 0.01) )
o = fix(o)
p = ( c / (1.58 + 0.01) )
p = fix(p)
q = o * p
q = fix(q)
ooo = num2str (o)
ppp = num2str (p)
qqq = num2str (q)
int16(qqq)
set(handles.BN1,'string',ooo)
set(handles.BN2,'string',ppp)
set(handles.BN3,'string',qqq)
n = a * max(z,q)
set(handles.CN,'string',n)
Hopefully you can see how fillmodule.m launches CUBA and then puts the 4 variables into CUBA's appdata.
Then, when you press the button in CUBA, the button's callback function executes and pulls those data back out of appdata to perform the calculation.
GUIs, handles, and callback functions can be confusing at first, but stick with it and refer to the documentation and you'll get a handle on it (no pun intended) pretty soon!

Sign in to comment.


Walter Roberson
Walter Roberson on 5 Nov 2016
You had a number of bugs in your GUI.
  • you had everything in a uibuttongroup instead of in a panel
  • you were using variables without having defined them
  • the way you were transferring data between the GUIs was clumsy
  • on PCs (but not Mac or Linux), typing into one of the inputs would have triggered a call to the undefined routine CUBA_Function
  • your code on the CUBA side was confused about whether it was dealing with handles or strings
  • you were letting a lot of intermediate calculations be output for no reason
  • you were transferring the string 'Maximum power' and trying to understand it as a number, instead of transferring 4 or '4K Watt' and pulling the number out of that.
I fixed all these things and attached the result, but I did not improve the overall design
I would suggest that you put input and output in the same figure until you have a lot more experience with GUIs. The way to communicate between GUIDE GUIs is not straight forward. Get accustomed to transferring data between callbacks first, before you try working with multiple GUIs.
  3 Comments
Walter Roberson
Walter Roberson on 5 Nov 2016
"A button group can contain any UI component type (except an ActiveX® control), but it only manages the selection of radio buttons and toggle buttons."
So there are no documented unwanted interactions for using a uibuttongroup. Undocumented... I don't know.
Nick Counts
Nick Counts on 6 Nov 2016
Perhaps a question for Yair

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!