0

I am working on a MATLAB GUI using App Designer, though perhaps my issue is similar to guide. What I would like to do is pass the output of one callback (button) into another. The reason is to be efficient with time; I want the user to be able to first load a file, and then choose which columns of data to plot.

I have tried establishing global variables, but that doesn't seem to work.

The objective of my project is to load XML files containing several dozen 'columns' of data with several hundred 'rows' of measurements (for example: temperature and humidity over time). My idea is that the user will push one button to load the data, then select the desired column(s) to be displayed.

methods (Access = private)

    % Button pushed function: SelectNewFileButton
    function SelectNewFileButtonPushed(app, event)
        [filename, filepath] = uigetfile('..\*.*');
        app.FileNameEditField.Value=filename;
        app.FilePathEditField_2.Value=filepath;
    end

    % Button pushed function: LoadDataButton
    function LoadDataButtonPushed(app, event)
        % Loads XML data...
        global xHead;
        % EM_witsfun1 is a function which takes a file name & directory as an input, and returns the header and data
        [xHead, xData, toc1]=EM_witsfun1(app.FileNameEditField.Value,app.FilePathEditField_2.Value);
        app.DataLoadedinsEditField.Value=toc1; % Shows elapsed time after running the above function (just to make sure it works)
    end

    % Button pushed function: UpdateButton
    function UpdateButtonPushed(app, event)
        app.ChosenChannelNameEditField.Value=xHead{app.ChooseChannelNumberEditField.Value};
    end
end

The error is:

undefined function or variable xHead.

Perhaps there is something defined outside the function that I can update within the function (just like I have done with a text box), but I'm not exactly sure what is the most elegant way to do that.

Image of GUI display:

Image of GUI display

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
J. Will
  • 13
  • 1
  • 3
  • I believe I solved my issue: rather than trying to establish new global variables, I updated the elements of existing GUI objects. For example, by passing the elements of a cell array into a list box: app.ListBox1.Items={'newString1','newString2'}; Thus the new elements of the ListBox are accessible throughout the application. I intend to do the same thing with data, though I am unsure how to do this without displaying all the data in a table (time consuming). – J. Will Aug 01 '17 at 22:52

1 Answers1

0

I solved my problem using public properties, as per Mathworks.

J. Will
  • 13
  • 1
  • 3
  • Hi! Please accept this answer indicating that the question is solved. More importantly, while the link may answer the question, it is better to include the essential parts of the solution here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Dev-iL Aug 13 '17 at 10:33