Hi,
I have problem to select an image folder in GUI. My GUI functions like that, when I push the selectSourceButton button I select the folder. Later, when I push the startButton the program should read all the files.
It seems my problem is how to transfer the Source folder information between the functions. I hope anyone can help me.
Thank you.
function selectSourceButton_Callback(hObject, eventdata, handles)
% hObject handle to selectSourceButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.output = hObject;
sourceFolder = uigetdir();
textLabel = sprintf('%s', sourceFolder);
set(handles.sourceFolderEdit, 'string', textLabel);
myFolder = get(handles.sourceFolderEdit, 'String');
guidata(hObject, handles);
function startButton_Callback(hObject, eventdata, handles)
handles.output = hObject;
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.jpg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
end

 채택된 답변

Image Analyst
Image Analyst 2013년 4월 8일

0 개 추천

I'd just use one folder - not myFolder and not sourceFolder. Just pick one and attach it to handles.
function selectSourceButton_Callback(hObject, eventdata, handles)
sourceFolder = uigetdir();
set(handles.sourceFolderEdit, 'string', sourceFolder );
handles.sourceFolder = sourceFolder;
guidata(hObject, handles);
function startButton_Callback(hObject, eventdata, handles)
if ~isdir(handles.sourceFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', handles.sourceFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(handles.sourceFolder, '*.jpg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(handles.sourceFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
end

댓글 수: 5

as hz
as hz 2013년 4월 9일
Thanks
geo i
geo i 2016년 4월 9일
Could anyone tell me why I get this error?
Reference to non-existent field 'sourceFolderEdit'.
Image Analyst
Image Analyst 2016년 4월 10일
They had an edit text box on their GUI called sourceFolderEdit - in other words, the "tag" property of the text edit box was sourceFolderEdit. If you want to do the same thing, you'll have to either call your edit box that, or replace the code with the actual name of the edit text box that you're using.
Ishwarya Subramanian
Ishwarya Subramanian 2017년 4월 6일
I'm using the above code..but i didnt get the images in sequential order. Can anyone please solve this
Image Analyst
Image Analyst 2017년 4월 6일
Not sure what sorting order you want. Perhaps it's this: http://blogs.mathworks.com/pick/2014/12/05/natural-order-sorting/

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

질문:

2013년 4월 8일

댓글:

2017년 4월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by