Getting value of selected string in Popup menu.

2 次查看(过去 30 天)
I am trying to make a GUI. Depending on the option selected in popup menu 3 the selected operation should be performed on images. However when i am trying to get the value from popupmenu3 I am getting the following error.
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)pr('popupmenu3_Callback',hObject,eventdata,guidata(hObject)).
Below is the code for this popupmenu.
function popupmenu3_Callback(hObject, eventdata, handles)
contents = get(hObject,'String');
a = contents{get(hObject,'Value')} ;
% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
When I make a simple GUI with only popupmenus I don't get the error. But when I try to get the value of selected string I am getting error.
  4 个评论
per isakson
per isakson 2017-5-2
编辑:per isakson 2017-5-2
  • You should always show the entire error message.
  • See Debug a MATLAB Program
  • This folder name looks strange to me
127 cd(handles.Dir.Functions_Dir)
K>> handles.Dir.Functions_Dir
ans =
D:\ÎÒµÄÎĵµ\MATLAB\Image Processing\Functions\
K>>
Sidra Aleem
Sidra Aleem 2017-5-2
@per isakson I saw the entire message. This name is strange to you because my desktop has Chinese as a language. That's why its appearing strange in your system. I have figured out my issue. I was misplacing some of my folder names.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-5-2
Your code does not protect against the possibility that there are no subdirectories in the selected directory. There are no prompts as to what the purpose of the selecting a directory is, so you should assume that users might select something with no subdirectories.
Your code should use fullfile() instead of splicing strings together in the line
handles.People(i).Images = ReadFileNames([handles.Dir.Home_Dir '\Inputs\' dirinfo(i,1).name]);
In Browse_Callback you do
foldername = uigetdir('D:\ÎÒµÄÎĵµ\MATLAB\Image Processing','Select folfer');
handles.fname=foldername;
which is fine in itself, and in pushbutton2_Callback you use handles.fname to refer to the selected directory and you find the sub-directories of that. But then just a few lines further down you use
cd(handles.Dir.Functions_Dir)
which assumes that handles.Dir.Functions_Dir is the same as handles.fname . Why bother to have two different variables for the same purpose? Why bother to ask the user what directory to use if you are always going to assume that handles.Dir.Functions_Dir refers to the same place? Or flip that around: if you bothered to ask the user what folder to use (perhaps because they are using a different machine where the folders are in a different location) then why are you are ignoring the user-selected folder name?
You do not need to do the cd() at all. You can use
handles.People(i).Images = ReadFileNames( fullfile(Input_Dir, dirinfo(i,1).name) );
By the way, in ReadFilenames, you should be using fullfile() instead of worrying about NameSeperator . Also, although it is not well known, internally MS Windows uses '/' as its directory separator, using '\' for public presentation. Because the real directory separator is '/' you can just always use '/' if you are going to code directory separators yourself -- but don't do that, use fullfile() instead.
  5 个评论
Walter Roberson
Walter Roberson 2017-5-4
You
cd(handles.Dir.Functions_Dir)
and later
cd ..
Are we certain that cvv.m is one directory level above Functions_Dir ? Let us look:
handles.Dir.Home_Dir = [handles.Dir.Present_Dir 'cvv\']; % Home Directory
handles.Dir.Functions_Dir = [ handles.Dir.Home_Dir 'Functions\' ]; %Functions Directory
One level above Functions_Dir is going to be Home_Dir, which is a directory named cvv . It is unlikely in MS Windows that you would be using both a directory named cvv and a file named cvv.m in the same directory..
Sidra Aleem
Sidra Aleem 2017-5-4
编辑:Walter Roberson 2017-5-4
@Walter Roberson with your help i figured out that after imwrite() the control went to Output folder. From there I was not moving the control to home directory.
cd(imagepath)
imwrite(images,[ Name ' -FFT_Result.jpg'], 'jpg');
So after this line I did
cd( (handles.Dir.Home_Dir)
And now its working fine. And Thanks for pointing out that .m file and directory files names are same I will change that as well. Thanks for your help.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 迁移使用 GUIDE 创建的 App 的更多信息

Community Treasure Hunt

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

Start Hunting!