Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
this is what i have so far
as you can see if i use save as i am using right now then i am saving the original image how would i save a modified image after applying one of the filters like black and white.
function varargout = testme(varargin)
% TESTME MATLAB code for testme.fig
% TESTME, by itself, creates a new TESTME or raises the existing
% singleton*.
%
% H = TESTME returns the handle to a new TESTME or the handle to
% the existing singleton*.
%
% TESTME('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TESTME.M with the given input arguments.
%
% TESTME('Property','Value',...) creates a new TESTME or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before testme_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to testme_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 testme
% Last Modified by GUIDE v2.5 13-Oct-2014 13:17:45
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #testme_OpeningFcn, ...
'gui_OutputFcn', #testme_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 testme is made visible.
function testme_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 testme (see VARARGIN)
% Choose default command line output for testme
handles.fileLoaded = 0;
handles.fileLoaded2 = 0;
%-----------------------------------------------------------------------
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes testme wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = testme_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 loadbutton.
function loadbutton_Callback(hObject, eventdata, handles)
% hObject handle to loadbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im im2
[path,user_cance]=imgetfile();
if user_cance
msgbox(sprintf('Error'),'Error','Error');
return
end
im=imread(path);
im=im2double(im); %converts to double
im2=im; %for backup process :)
axes(handles.axes1);
imshow(im);
axes(handles.axes2);
hist(im);
%-----------------------------------------------------------------------
% --- Executes on button press in resetbutton.
function resetbutton_Callback(hObject, eventdata, handles)
% hObject handle to resetbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im2
axes(handles.axes1);
imshow(im2);
axes(handles.axes2);
hist(im2);
% --- Executes on button press in negativebutton.
function negativebutton_Callback(hObject, eventdata, handles)
% hObject handle to negativebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
imblack=im;
imblack=1-im;
axes(handles.axes1);
imshow(imblack);
axes(handles.axes2);
hist(imblack);
% --- Executes on button press in greybutton.
function greybutton_Callback(hObject, eventdata, handles)
% hObject handle to greybutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
imgray=(im(:,:,1)+im(:,:,2)+im(:,:,2))/3;
axes(handles.axes1);
imshow(imgray);
axes(handles.axes2);
hist(imgray);
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global im2
val=0.5*get(hObject,'Value')-0.5;
imbright=im2+val;
axes(handles.axes1);
imshow(imbright);
axes(handles.axes2);
hist(imbright);
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in savebutton.
function savebutton_Callback(hObject, eventdata, handles)
% hObject handle to savebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[file,path]=uiputfile({'*.bmp','BMP'},'Save Image As');
f=getframe(handles.axes1);
[x,map]=frame2im(f);
imwrite(x,fullfile(path, file),'bmp');
% --- Executes on button press in black.
function black_Callback(hObject, eventdata, handles)
% hObject handle to black (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
global im
xb=im;
b=im2bw(xb);
imshow(b);
There are several ways to do this, but maybe a good way is to store the image (after applying a filter) in the figure's application data. You can do this with guidata.
After each filter you store the image;
% --- Executes on button press in black.
function black_Callback(hObject, eventdata, handles)
% hObject handle to black (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
global im
xb=im;
b=im2bw(xb);
imshow(b);
% Store the image
handles.image = b;
guidata(hObject, handles);
Then in your savebutton_Callback, simply refer to handles.image;
Related
I am having hard time to make slider to behave as a progress bar.
I have two push buttons. One accepts the starting value from a text editor(User Input) and other start the progress of the loop.
Then I have got a slider, which I am trying to move as the function loop changes 'i' value(Update along/show progress).
This is my code.
function varargout = myfig(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #myfig_OpeningFcn, ...
'gui_OutputFcn', #myfig_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 myfig is made visible.
function myfig_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 myfig (see VARARGIN)
% Choose default command line output for myfig
handles.output = hObject;
handles.min = get(handles.ed,'value');
handles.max = 10000;
handles.i = 0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes myfig wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = myfig_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 pb.
function pb_Callback(hObject, eventdata, handles)
% hObject handle to pb (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
value = str2double(get(handles.ed,'string'));
value
assignin('base','value',value)
% --- Executes on slider movement.
function sl_Callback(hObject, eventdata, handles)
% hObject handle to sl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.sl,'Max',handles.max);
set(handles.sl,'min',handles.min);
set(handles.sl,'value',handles.i);
% --- Executes during object creation, after setting all properties.
function sl_CreateFcn(hObject, eventdata, handles)
% hObject handle to sl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function ed_Callback(hObject, eventdata, handles)
% hObject handle to ed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of ed as text
% str2double(get(hObject,'String')) returns contents of ed as a double
% --- Executes during object creation, after setting all properties.
function ed_CreateFcn(hObject, eventdata, handles)
% hObject handle to ed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
% --- Executes on button press in pbs.
function pbs_Callback(hObject, eventdata, handles)
% hObject handle to pbs (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
myfile;
function [] = myfile(handles)
%MYFILE Summary of this function goes here
% Detailed explanation goes here
% prompt('Please enter a valid number to start');
h = waitbar(0,'Processing...');
% i = input('Please enter a valid number to start');
i = evalin('base','value');
while(i < 10000)
clc
i = i + 1;
waitbar(i/10000,h)
handles.i = i;
set(handles.sl,'value',i/10000);
guidata(hObject,handles);
end
close(h);
Matlab verstion: 2014b
First: I want to learn how can I handle this when function is nested inside the GUI file.
Second: If you move the function into a different .m file.[Using set/get/guidata etc... and not passing input/output with function call]
Please let me know.
For the first case, you will need to modify your function myfile. Before the while loop, you'll need to set the min and max of the slider. This will allow you to use i as your value.
set(handles.sl,'Min',1,'Max',10000);
To allow the slider to update, you will need to add refresh and drawnow inside your loop. Matlab will wait to draw ui changes until the end of your code if you so not use these. Your loop should look like the following:
while(i < 10000)
clc
i = i + 1;
waitbar(i/10000,h)
set(handles.sl,'value',i/10000);
refresh;
drawnow;
end
From personal experience, the second case can get messy for larger applications. I would recommend creating your application using object oriented programming if you need to use more than one file. You could store ui handles in the objects you create, which keeps your code organized and makes it easier to pass handles back and forth.
I am trying to create a GUI using GUIDE where it allows the user to pick one of two pushbuttons. The strings in the pushbuttons will vary each time (I haven't automated this yet), but when any of the pushbuttons is pushed, I'd like the GUI to put out the string as an output variable.
I have the code to where it shows the output in the workspace, but the handles are deleted before the OutputFn is called. Any suggestions on how to fix this?
Also, I'd like to use a 'Next' button. Ideally this should pull up the next two texts to be displayed on the pushbuttons, in an iterative manner, but I'd be happy to move past the hurdle of getting the output for now.Here is what I have so far:
function varargout = Select_A_B(varargin)
% SELECT_A_B MATLAB code for Select_A_B.fig
% SELECT_A_B, by itself, creates a new SELECT_A_B or raises the existing
% singleton*.
%
% H = SELECT_A_B returns the handle to a new SELECT_A_B or the handle to
% the existing singleton*.
%
% SELECT_A_B('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SELECT_A_B.M with the given input arguments.
%
% SELECT_A_B('Property','Value',...) creates a new SELECT_A_B or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Select_A_B_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Select_A_B_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 Select_A_B
% Last Modified by GUIDE v2.5 18-Jun-2015 15:12:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #Select_A_B_OpeningFcn, ...
'gui_OutputFcn', #Select_A_B_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 Select_A_B is made visible.
function Select_A_B_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 Select_A_B (see VARARGIN)
% Choose default command line output for Select_A_B
handles.output = hObject;
handles.string = '';
if isempty(varargin)
varargin{1} = 1;
varargin{2} = 1;
end
text1 = varargin{1};
text2 = varargin{2};
A = {'Apple';'Orange'};
B = {'Football';'Basketball'};
set(handles.pushbutton1,'string',A(text1)); % wait until we're ready
set(handles.pushbutton2,'string',B(text2)); % wait until we're ready
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Select_A_B wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Select_A_B_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} = hObject;
varargout{2} = handles.string;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selectedButton = get(hObject,'String')
set(handles.string,'String',selectedButton);
guidata(hObject, handles);
close(gcf);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selectedButton = get(hObject,'String')
set(handles.string,'String',selectedButton);
guidata(hObject, handles);
close(gcf);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (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 pushbutton1_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
I have the answer to my question. A summary of changes:
Added uiresume (after adding uiwait in the Opening function) after each Callback
Deleted close (gcf) after each Callback; if the figure closes, then hObject and handles in guidata are no longer accessible to the Output function
Created a handle structure to contain the text of interest and saved that in
guidata after each Callback function
Saved the output from guidata to a .mat file in the Output function
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selectedButton = get(hObject,'String')
handles.string = selectedButton;
guidata(hObject, handles);
uiresume(handles.figure1);
% close(gcf);
function varargout = Select_A_B_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} = hObject;
varargout{2} = handles.string;
save 'guioutput'
delete(hObject)
Learnings from the post experience:
I should’ve been more specific regarding my question. Hopefully I’ll
get better with more experience and learning the correct ‘lingo’ to
use.
I should’ve pointed out in my first post that I did spend
considerable time looking at multiple blogs and sites on Matlab GUI,
guide, and guidata. Frankly, none of the sites that I found addressed
my specific question.
This post is the one that finally helped me figure out my mistake:
http://www.mathworks.com/matlabcentral/answers/141809-issue-with-gui-editbox-callback
Okay, first is, sorry if this question seems stupid for you. I'm not really a fan of matlab but I have to use it for my assignment. I want to export or save the result of imageinfo function to a doc or csv format. I have searched it and found some solutions but nothing works on my project. Thank you so much for helping me!
and this is my code
function varargout = ws(varargin)
% WS MATLAB code for ws.fig
% WS, by itself, creates a new WS or raises the existing
% singleton*.
%
% H = WS returns the handle to a new WS or the handle to
% the existing singleton*.
%
% WS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in WS.M with the given input arguments.
%
% WS('Property','Value',...) creates a new WS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ws_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ws_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 ws
% Last Modified by GUIDE v2.5 20-Feb-2015 02:37:50
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #ws_OpeningFcn, ...
'gui_OutputFcn', #ws_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 ws is made visible.
function ws_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 ws (see VARARGIN)
% Choose default command line output for ws
handles.output = hObject;
%Membuat background
ah= axes ('unit','normalized','position', [0 0 1 1]);
%Membaca gambar
bg= imread('large1.jpg');imagesc(bg);
%Supaya background tidak mengintervensi data
set(ah,'handlevisibility','off','visible','off')
%Memastikan tombol lain diatas background
uistack(ah,'bottom');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ws wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ws_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 pushbutton1.
% --- Fungsi untuk mengambil gambar yang ingin digunakan
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles=guidata(gcbo); %This MATLAB function stores the variable data as GUI data
[nama_file,direktori]=uigetfile({'*.jpg';'*.bmp';'*.png';'*.tif';'*.jpeg'}) %Fungsi untuk mengambil gambar dan Format file yang dapat dideteksi oleh program
cd(direktori); %agar dapat mengambil file dari berbagai direktori
if isequal(nama_file,0)
return;
end
eval(['cd ''' direktori ''';']); %pembacaan path directory agar sesuai direktori yang digunakan untuk mengambil file.
I=imread(nama_file);
set(handles.figure1,'CurrentAxes',handles.axes1); %Meletakkan gambar yang dipilih pada axes1
set(imshow(I));
set(handles.figure1,'Userdata',I);
set(handles.axes1,'Userdata',I);
imageinfo(nama_file);
set(handles.text1,'String','Berikut ini adalah informasi dari gambar yang Anda pilih');
info = getframe(gcf);
assignin('base','info',info); %mengexport variabel hasil
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Program save file MAT
info=evalin('base','info'); %memanggil variabel hasil
%project=guidata(gcbo);
[nama_file,direktori]=uiputfile({'*.jpg';'*.*'},'Simpan Citra');
imwrite(info.cdata,strcat(direktori,nama_file));
%xlswrite(nama_file, T.cdata, 1);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles);
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close all
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
I can't test it now, but check if imfinfo http://mathworks.com/help/matlab/ref/imfinfo.html has the information that you need - a struct should be easier to write respect to a tool figure!
I want to create a graphical interface with the GUIDE Matlab that displays diffrent responses of a transfer function : step , impulse , bode , nyquist and nichols responses.
it works fine for the step and impulse responses but with nyquist , bode and nichols it dosen't work , i should add 'squeeze' to the 'plot' function but it's not exactly the correct response !
this is the error when i try with plot only :
??? Error using ==> plot Data may not have more than 2 dimensions
This is th LTI.fig file
The following code is the content of the .m file
function varargout = LTI(varargin)
% LTI M-file for LTI.fig
% LTI, by itself, creates a new LTI or raises the existing
% singleton*.
%
% H = LTI returns the handle to a new LTI or the handle to
% the existing singleton*.
%
% LTI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LTI.M with the given input arguments.
%
% LTI('Property','Value',...) creates a new LTI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before LTI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to LTI_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 LTI
% Last Modified by GUIDE v2.5 24-Nov-2014 10:41:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #LTI_OpeningFcn, ...
'gui_OutputFcn', #LTI_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 LTI is made visible.
function LTI_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 LTI (see VARARGIN)
% Choose default command line output for LTI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes LTI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = LTI_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;
function numerateur_Callback(hObject, eventdata, handles)
% hObject handle to numerateur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of numerateur as text
% str2double(get(hObject,'String')) returns contents of numerateur as a double
% --- Executes during object creation, after setting all properties.
function numerateur_CreateFcn(hObject, eventdata, handles)
% hObject handle to numerateur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
function denumerateur_Callback(hObject, eventdata, handles)
% hObject handle to denumerateur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of denumerateur as text
% str2double(get(hObject,'String')) returns contents of denumerateur as a double
% --- Executes during object creation, after setting all properties.
function denumerateur_CreateFcn(hObject, eventdata, handles)
% hObject handle to denumerateur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
% --- Executes on button press in rep_indic.
function rep_indic_Callback(hObject, eventdata, handles)
% hObject handle to rep_indic (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
plot(step(G))
grid on
% --- Executes on button press in lieu_bode.
function lieu_bode_Callback(hObject, eventdata, handles)
% hObject handle to lieu_bode (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
plot(squeeze(bode(G)))
grid on
% --- Executes on button press in rep_impuls.
function rep_impuls_Callback(hObject, eventdata, handles)
% hObject handle to rep_impuls (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
plot(impulse(G))
grid on
% --- Executes on button press in lieu_nyquist.
function lieu_nyquist_Callback(hObject, eventdata, handles)
% hObject handle to lieu_nyquist (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
plot(s(nyquist(G)))
grid on
% --- Executes on button press in lieu_nichols.
function lieu_nichols_Callback(hObject, eventdata, handles)
% hObject handle to lieu_nichols (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
plot(squeeze(nichols(G)))
grid on
You don't provide the *.fig file to go with your code, but I suspect I know what the problem is: bode, nyquist and nichols produce the plot automatically, you don't need to call the plot function. Check the documentation for the correct way to call these functions. In your GUI, replace:
plot(squeeze(bode(G))) by bode(G)
plot(s(nyquist(G))) [sic] by nyquist(G)
plot(squeeze(nichols(G))) by nichols(G)
EDIT based on comments
I think all you need to do is
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
step(G)
grid on
and the same applies for bode, nyquist, nichols and impulse, i.e. just create a set of axes in the figure and the plot will be displayed in those axes by default.
let us consider following program for graphical user interface
function varargout = quadratic(varargin)
% QUADRATIC MATLAB code for quadratic.fig
% QUADRATIC, by itself, creates a new QUADRATIC or raises the existing
% singleton*.
%
% H = QUADRATIC returns the handle to a new QUADRATIC or the handle to
% the existing singleton*.
%
% QUADRATIC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in QUADRATIC.M with the given input arguments.
%
% QUADRATIC('Property','Value',...) creates a new QUADRATIC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before quadratic_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to quadratic_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 quadratic
% Last Modified by GUIDE v2.5 23-Jul-2014 18:00:48
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #quadratic_OpeningFcn, ...
'gui_OutputFcn', #quadratic_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 quadratic is made visible.
function quadratic_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 quadratic (see VARARGIN)
% Choose default command line output for quadratic
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes quadratic wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = quadratic_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 edit1.
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
function b_Callback(hObject, eventdata, handles)
% hObject handle to b (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of b as text
% str2double(get(hObject,'String')) returns contents of b as a double
% --- Executes during object creation, after setting all properties.
function b_CreateFcn(hObject, eventdata, handles)
% hObject handle to b (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
function c_Callback(hObject, eventdata, handles)
% hObject handle to c (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of c as text
% str2double(get(hObject,'String')) returns contents of c as a double
% --- Executes during object creation, after setting all properties.
function c_CreateFcn(hObject, eventdata, handles)
% hObject handle to c (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=str2num(get(handles.a,'String'));
b=str2num(get(handles.b,'String'));
c=str2num(get(handles.c,'String'));
d=b^2-4*a*c;
if (d>0)
X1=(-b+sqrt(d))/(2*a);
X2=(-b-sqrt(d))/(2*a);
set(handles.x1,'String',X1)
set(handles.x2,'String',X2)
elseif (d==0)
X1=(-b+sqrt(d))/(2*a);
set(handles.x1,'String',X1)
set(handles.x2,'String',X1)
else
set(handles.x1,'String','roots are complex')
set(handles.x2,'String','roots are complex')
end
function x1_Callback(hObject, eventdata, handles)
% hObject handle to x1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of x1 as text
% str2double(get(hObject,'String')) returns contents of x1 as a double
% --- Executes during object creation, after setting all properties.
function x1_CreateFcn(hObject, eventdata, handles)
% hObject handle to x1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
function x2_Callback(hObject, eventdata, handles)
% hObject handle to x2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of x2 as text
% str2double(get(hObject,'String')) returns contents of x2 as a double
% --- Executes during object creation, after setting all properties.
function x2_CreateFcn(hObject, eventdata, handles)
% hObject handle to x2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
function a_Callback(hObject, eventdata, handles)
% hObject handle to a (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of a as text
% str2double(get(hObject,'String')) returns contents of a as a double
% --- Executes during object creation, after setting all properties.
function a_CreateFcn(hObject, eventdata, handles)
% hObject handle to a (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
this program simple will allow to enter coefficients of quadratic equation and then solve equation and try to find roots,how can i take screenshot of GUI interface after this program?please help me,i want to save figure which occurs after running of this program,thanks in advance
One of the quick and dirty approaches
myGUI = quadratic;
% ......
% do something or wait until it's done...
% ......
print(myGUI, '-dpng', 'GUIOUT.png'); % save as .png
print(myGUI, '-djpeg', 'GUIOUT.jpg'); % save as .jpg
It will work fine if you only take a screenshot.
However, if you encounter the problem for which the output picture does not have the same size as the figure on your screen (especially when saving as pdf), you will probably have to implement solutions describled in
this article.
or even better using fig2file may work for you.