Borrar filtros
Borrar filtros

Inserting a picture on a GUI

16 visualizaciones (últimos 30 días)
Bryce Heventhal
Bryce Heventhal el 10 de Mzo. de 2011
I am doing a GUI for my final project except i can't figure out how to make an image show up. I have tried multiple ways but here looks to be the most successful
I have been creating an axes then creating a callback for that axis. I then edited a few lines to create this:
% --- Executes during object creation, after setting all properties.
function Axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate Axes1
Axes1(hObject)
imshow('MSD.tif')
I need an image of a Spring-Mass-Damper system.
I tried following the video created by doug hull.

Respuestas (3)

Sean de Wolski
Sean de Wolski el 20 de Abr. de 2012

Walter Roberson
Walter Roberson el 10 de Mzo. de 2011
You would not use Axes1(hObject): you would use axes(hObject)
Or better yet, skip the axes() call and use
imshow(hObject,'MSD.tif')
  12 comentarios
Reza
Reza el 23 de Abr. de 2012
Sorry! I am not trying to ignore anyone. I just have not done this before. I guess my main misunderstanding is from the concept of handles and callback. I have put together a gui in which I like to be able to type in a file name that I can use to output my results into. Then there are two buttons to perform different tasks. Now, I have not quite figured out how to inquire for the output file name and definitely I do not know how to have a logo image on this gui (the problem at hand). I'll follow whatever advice that allows my doing that. What you see is my understanding of your advice, which could be misunderstood version of it. Here is my entire code. Thanks.
function varargout = FastDD(varargin)
% FastDD M-file for FastDD.fig
% FastDD, by itself, creates a new FastDD or raises the existing
% singleton*.
%
% H = FastDD returns the handle to a new FastDD or the handle to
% the existing singleton*.
%
% FastDD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FastDD.M with the given input arguments.
%
% FastDD('Property','Value',...) creates a new FastDD or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before FastDD_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to FastDD_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help FastDD
% Last Modified by GUIDE v2.5 23-Apr-2012 18:09:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FastDD_OpeningFcn, ...
'gui_OutputFcn', @FastDD_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before FastDD is made visible.
function FastDD_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to FastDD (see VARARGIN)
% Choose default command line output for FastDD
handles.output = hObject;
MyImage=imread('reza.jpg');
imshow(MyImage, 'Parent', handles.axesImage);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes FastDD wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = FastDD_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in RunTask.
function RunTask_Callback(hObject, eventdata, handles)
% hObject handle to RunTask (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 CalcDD.
function CalcDD_Callback(hObject, eventdata, handles)
% hObject handle to CalcDD (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function SubjData_CreateFcn(hObject, eventdata, handles)
% hObject handle to SubjData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
function SubjData_Callback(hObject, eventdata, handles)
% hObject handle to SubjData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%FileID = get(hObject,'String');
Image Analyst
Image Analyst el 23 de Abr. de 2012
Reza, this is getting rather extensive so you should start your own thread rather than piggybacking onto Bryce's thread. I'll solve your problem if you do that.

Iniciar sesión para comentar.


Jakob Sørensen
Jakob Sørensen el 24 de Abr. de 2012
Also, don't confuse the name of the axes, which is axes1 by default (or handles.axes1 for the full name), with the axes() command. So if you wan't to chose the axes, named axes1, the syntax is:
axes(handles.axes1)
Also, you can use guide (and its property editor), to rename the axes, to avoid confusing yourself.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by