Hello, I'm looking to have a static text or edit text box change it's value depending on what I put in for the other edit text boxes in a GUI

Hello, I don't want to have to press a button to get the value in a static or edit text box to change. I want the value to change as I change other values (like excel) with out a push-button in my GUI. I got it to work for a brief moment by placing the code under the function
SIMPLE_FO_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
while(1)
pause(1)
F_SW_in_i_max = str2double(get(handles.F_SW_in_max,'string'));
DSin_i_max = str2double(get(handles.DSin_i_max,'string'));
SWin_i_max = str2double(get(handles.SWin_i_max,'string'));
Water_recov = str2double(get(handles.Percent_water_recov,'string'));
min_draw = # (some value);
set(handles.Min_Draw_flow, 'string', num2str(min_draw)); end

2 Comments

What mechanism are you using to change the variables? Are they being changed in a gui? Do you need the change to take effect every time some variable is modified in the code, without the code needing to have to specifically give notification to look for a new value?
It's in a GUI. i just want it to act like excel where you change a value and the others that call to that value change as well automatically. this is all done in matlab. right now the code above works, but i need to click in every box to get them to update. I just want them to update on their own.

Sign in to comment.

 Accepted Answer

I don't think this is easy. For you to type in Excel and have something happen in MATLAB to a static text label or an edit field or anywhere else, or run a MATLAB function, you'd have to use ActiveX, though there is an MATLAB Builder EX product and a Spreadsheet Link EX product that might help. I've not used those so you'd best call them and ask if it will do what you want. I'm pretty sure MATLAB can act as an ActiveX server so if you have a macro in Excel that you used VBA to create, then you can use the key up event in the edit box of your macro's edit field to send an ActiveX command to your MATLAB GUI, though again, I haven't done that. If you're not typing in Excel into your own GUI, but typing into a regular old Excel cell, then I think your only help is if one of those two products can help you.
One other thought would be to set up a timer to talk to Excel via ActiveX. You could get the active cell the user is on, then haul over that cell's contents, inspect it, and take some action based on that, such as writing it to a static text label on your MATLAB GUI.

3 Comments

Sorry not trying to use excel. i just my GUI to act like excel where you change a value in a box and the other boxes that call to that cell change automatically. This is all done in my matlab GUI
Since there is no "lost focus" event in MATLAB, that won't work. Perhaps you can put the recalculate code in the callback function for the keypress event so that every time you press a key for an edit field, it will call the function which will perform the necessary calculations. Of course every edit field where you want that to happen will also have to have a keypress function defined where they all call the same "recalculate" function.

Sign in to comment.

More Answers (1)

You can do a Get the value from the first Text Box every time it is edited by using edit Call Back function using
RecievedString=get(handles.Box1, 'String')
Update your Text Box 2 immediately. set(handles.Box2, 'String', RecievedString)

Tags

Community Treasure Hunt

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

Start Hunting!