MATLAB App Designer: Passing output from one button to another

3.8k Views Asked by At

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

1

There are 1 best solutions below

1
On

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