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
Kevin Chng
2018년 10월 13일
편집: Kevin Chng
2018년 10월 13일
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.
gage benham
2018년 10월 17일
Kevin Chng
2018년 10월 17일
편집: Kevin Chng
2018년 10월 17일
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?
gage benham
2018년 10월 19일
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
2018년 10월 20일
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
endTherefore, i gues now your apps is more dynamically even you have more variable in your mat.file.
카테고리
도움말 센터 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!