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

조회 수: 2 (최근 30일)
gage benham
gage benham 2018년 10월 13일
댓글: Kevin Chng 2018년 10월 20일
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
gage benham
gage benham 2018년 10월 19일
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?
Kevin Chng
Kevin Chng 2018년 10월 20일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Kevin Chng
Kevin Chng 2018년 10월 20일

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.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by