How to set ItemsData using external file (App Designer)?

The purpose of my app is to create a UI which allows the user to select data they want to graph through a drop-down menu and adjust the graph to their liking through a series of edit fields. However, I am currently having trouble setting the ItemsData of my drop-down menu to the array variable from an external .mat file. Some of the difficulty stems from this being a multiwindowed app (based heavily on this tutorial). I am currently able to load the .mat file, but I can't figure out how to pass the array data to the popup window class and set it as an ItemData for the drop-down window. Attached are .txt files for both the main window and the popup window.
I greatly appreciate any suggestions on how to solve this.

5 Comments

Hi gage benham,
i guess your problem is here
app.EcogDropDown.Value = i_ecog;
May i know what the data type of i_ecog? numeric?string? for the property(value) of dropdown , it only accept string.
How to set your array data as ItemData for the drop-down window?
Personally, i feel it is unnecessary to do it, since you had passed the i_ecog variable to the startup function of your dialog box, unless you have valid reason for it. for example, your data type of i_ecog is numeric loaded from your mat file.
In my first glance, your code should working fine to pass the information from your main window to dialog box. Since you are loading data from file, hence i'm unsure whether i_ecog is correct data type.
you may try, in your modifiedExample (mainapp)
properties (Access = public)
DialogApp
%varA = ModifiedExample.var.ecog;
%varB = ModifiedExample.var.ecog_t;
%varC = ModifiedExample.var.c_ecog;
%var;
%Current_ecog = ModifiedExample.var.ecog;
Current_ecog = 'c_ecog';
Current_height = 0.003;
Current_yGap = 0.004;
Current_tStart = 0;
Current_tEnd = 7;
Current_yHeight = 0;
end
assign proper data type (string) to the Current_ecog, then run your code. You will notice the dropdown of your dialog app will follow the string that you are assigned.
Thank you Kevin, I really appreciate your answer. I apologize for not clarifying the meaning behind the variables in my code. The .mat file that I load in the line
ModifiedExample.var = load(uigetfile('.mat','Select the MATLAB code file'));
app.Current_ecog = ModifiedExample.var.ecog;
contains several variables. The variable I assign to Current_Ecog, ecog, is an extremely large array of electrocorticography data. This is then plotted to the users liking using the 'cc' function. The need for a drop-down menu comes from there being multiple arrays of electrocorticography data (c_ecog and ecog_t). The drop-down allows the user to graph the array of their choosing. The issue now is associating the data from each array to a separate string option in the drop-down menu. However, you explained that the value of a drop-down only accepts string data types. The question now becomes what I can do to work around that?
Hi gage benham,
Therefore,
ModifiedExample.var = load(uigetfile('.mat','Select the MATLAB code file'));
The code above will load all your variable including ecog,c_ecog,ecog_t. Am i right?
Later user may click on the button "plot option" to select which variable they want to plot from the dropdown menu.
Your Question:
"The issue now is associating the data from each array to a separate string option in the drop-down menu. However, you explained that the value of a drop-down only accepts string data types."
1) load the variable in main window, get the variable names, and then display them in the dropdown menu of popup window/dialog window.
Do you need this? Or the option is fixed for the dropdown menu?
2) User Select the options from dropdown menu, then pass the selection back to main window, so that the main window (cc function) can recognize which array to plot in the axes.
Did i Intepret it correctly?
Yes, thank you for encapsulating what I'm struggling to say. Ultimately I removed the Pop-up window functionality entirely and just had a single app to simplify things. I was also able to associate my data to the chosen dropdown value through a series of conditional statements
if strcmp(app.EcogDropDown.Value,'ecog')
app.Current_ecog = app.varA;
elseif strcmp(app.EcogDropDown.Value,'c_ecog')
app.Current_ecog = app.varB;
elseif strcmp(app.EcogDropDown.Value,'ecog_t')
app.Current_ecog = app.varC;
end
effectively answering my original question. However, I would like to improve upon this by dynamically loading both the .mat variables and the drop down options instead of hard coding them as such
app.varA = app.var.ecog;
app.varB = app.var.c_ecog;
app.varC = app.var.ecog_t;
And have all the variables in the matlab file be assigned automatically. Do you know how I would go about this?
Hi gage benham, refer to my answer for it.
I recommend you modify your title so that it is not so confusing if people search for relevant solution.

Sign in to comment.

Answers (1)

Hi gage benham,

1st Step :

load your mat file. Make all the variable display in your drop menu automatically.

filename = whos(matfile('aaa.mat'));
            w=load('aaa.mat')
            for i =1:1:numel(filename)
                A(i) = cellstr(filename(i).name);
                app.var(i) = w.(A{i})
            end       
app.DropDown.Items =  cellstr(A);

in first step, you are assignig all value of variable into app.var. You might need to expand the dimension of app.var(i) if needed

2nd Step :

In your call back function for plot

    for i=1:1:numel(filename)
                  if  strcmp(app.DropDown.Value,filename(i).name)
                     plot(var(i)) 
                  end
    end

Therefore, i gues now your apps is more dynamically even you have more variable in your mat.file.

Categories

Products

Release

R2017b

Asked:

on 13 Oct 2018

Commented:

on 20 Oct 2018

Community Treasure Hunt

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

Start Hunting!