필터 지우기
필터 지우기

How to show an image once starting GUI

조회 수: 3 (최근 30일)
ws
ws 2011년 11월 18일
Hi all
I set code below on axes_background_CreateFcn, it works fine, but sometimes I re-run the GUI, axes tag will become blank and unable to show my image.
function axes_background_CreateFcn(hObject, eventdata, handles)
axes(hObject);
imshow('main_bg.jpg');

채택된 답변

Image Analyst
Image Analyst 2011년 11월 19일
I think it's best if you put the imshow() in the OpeningFcn() rather than the create function. The OpeningFcn is the function where you're supposed to put all your startup code - see the comments for it.
Other problems with your code are that
1. You failed to use the full file name by using fullfile() to prepend the folder. See the FAQ ( http://matlab.wikia.com/wiki/FAQ#Where_did_my_file_go.3F_The_risks_of_using_the_cd_function. )
2. You failed to check for existence of the file with the exist(fullFileName, 'file') function.
3. You failed to use try/catch,
try
fullFuleName = fullfile(folder, 'main_bg.jpg');
if exist(fullFileName, 'file)
imshow(fullFilename);
else
errorMessage = sprintf('Error: file does not exist:\n%s', fullFileName);
uiwait(warndlg(errorMessage));
end
catch ME
% Some general error.
errorMessage = sprintf('Error in function axes_background_CreateFcn.\n\nError Message:\n%s', ME.message);
uiwait(warndlg(errorMessage));
end
You can improve the robustness of your code if you read and follow the guidelines here: http://www.mathworks.com/matlabcentral/answers/1148-how-to-learn-matlab

추가 답변 (1개)

ws
ws 2011년 11월 20일
Hi guys
I'm not sure the method used is correct, but I have my image to appear on my main uipanel:
function axes_background_CreateFcn(hObject, eventdata, handles)
axes(handles.axes21)
imshow('main_bg.jpg')
:)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by