Note that there are some explanatory texts on larger screens.

plurals
  1. POGlobal variables set in GUI with no values - Matlab
    text
    copied!<p>I created a GUI to set parameters and use those parameters in another m-File. I know that the variables created in GUI are in a different workspace from the input variables to the m-File. For that reason, I'm trying to use <code>global variables</code>, but not sucesfully: the variables goes to the m-File empty.</p> <p>I have a GUI which has 3 edit boxes, that the user can set parameters (0 or 1), using this code (showing the code for only one edit box):</p> <pre><code>function density_Callback(hObject, eventdata, handles) % hObject handle to density (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of density as text % str2double(get(hObject,'String')) returns contents of density as a double global density density = str2double(get(hObject, 'String')); global Variavel_1 assignin('base', 'Variavel_1', density); </code></pre> <p>The m-File are called from a GUI BUTTON, using this code: </p> <pre><code>function calculate_Callback(hObject, eventdata, handles) % hObject handle to calculate (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) test %m-File that uses variables set in GUI </code></pre> <p>And the m-File should use this <code>Variavel_1</code> and the others from the remaining editboxes in this code (test.m):</p> <pre><code>global Variavel_1 global Variavel_2 global sum Variavel_1 Variavel_2 sum = Variavel_1 + Variavel_2 </code></pre> <p>But all I have is all those variables empty! (I know I can put this code inside the GUI code, but that's not the real propouse because this simple m-File to sum will be much more complex, so I need the variables to go to a m-File).</p> <pre><code>Variavel_1 = [] Variavel_2 = [] Sum = [] </code></pre> <p>Can anyone understand why the global variables fails?</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload