Populate one pop up menu on the basis of selection in another pop up menu.

1 visualizzazione (ultimi 30 giorni)
Hello
I have two popup menus. popup menu1 : Directory and popup menu2: File names. In pop up menu 1 directory names should appear and in popup menu 2 Files in that directory should appear.
However, when I click any of the directory names in popup menu 1 then only the file names in first directory are being displayed. Please help me.
for i = 1 : size(dirinfo,1)
%Reading names of People
People(i).Name = dirinfo(i,1).name;
text{i}= People(i).Name;
%Reading files of all people in structure format
cd(Functions_Dir)
People(i).Image_Name = ReadFileNames([Home_Dir '\Inputs\' dirinfo(i,1).name]);
text1{i}= People(i).Image_Name ;
cd ..
end
set(handles.popupmenu1,'string',text);
a=get(handles.popupmenu1,'value');
switch a
case 1
tex= text1{1};
case 2
tex= text1{2};
end
set(handles.popupmenu2,'string',tex);

Risposte (1)

ES
ES il 22 Mar 2017
In call back of popupmenu1 you should write this..
a=get(handles.popupmenu1,'value');
switch a
case 1
tex= text1{1};
case 2
tex= text1{2};
end
set(handles.popupmenu2,'string',tex);
is this done? I am not able to see the functions in your code. That is why I am clarifying.
  7 Commenti
Jan
Jan il 22 Mar 2017
@Sidra: It is not easy to guess, what exactly "the first directory" is. Remember that I do not have the faintest idea about what you are doing.
I assume the problem appears at the location, where you define, what the "first" and "second" directory is. Where does this happen?
Do you know how to step through the code using the debugger?
Sidra Aleem
Sidra Aleem il 23 Mar 2017
Modificato: Sidra Aleem il 23 Mar 2017
This part of the code takes directory names and displays them in first popup menu. I commented this part as well as is getting peoples names(directory names).
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in Process_Batch.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to Process_Batch (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isfield(handles,'fname')
Present_Dir = 'D:\我的文档\MATLAB\'; %Present Working Directory
Home_Dir = [Present_Dir '\Image Processing']; % Home Directory
Functions_Dir = [ Home_Dir '\Functions' ]; %Functions Directory
Input_Dir=handles.fname;
dirinfo = dir(Input_Dir);
dirinfo(~[dirinfo.isdir]) = []; %remove non-directories
tf = ismember( {dirinfo.name}, {'.', '..'}); %remove current and parent directory.
dirinfo(tf) = []; %remove current and parent directory.
for i = 1 : size(dirinfo,1)
%Reading names of Directory
People(i).Name = dirinfo(i,1).name;
text{i}= People(i).Name;
end
set(handles.popupmenu1,'string',text)
end

Accedi per commentare.

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by