how to use of GUI?
2 views (last 30 days)
Show older comments
for example I have a matrix X. lets say
X=rand(10)
then I wrote something like this as GUI
function [] = Mohammad()
M = figure('units','pixels',...
'position',[500 500 200 50],...
'menubar','none',...
'numbertitle','off',...
'name','Mohammad',...
'resize','on')
whitebg(M,'r')
set(M,'Position',[500 500 400 300])
m = uimenu('Label','&File');
uimenu(m,'Label','Open','Callback',{@fm});
uimenu(m,'Label','Quit','Callback','close',...
'Separator','on','Accelerator','Q');
function [] = fm(varargin)
% Callback for the figure menu.
[filename, pathname] = uigetfile({'*.mat', 'All MAT-Files (*.mat)';'*.*','All Files (*.*)'},'Open file');
end
end
right now, I want while I am loading the data by the "open" from my GUI, it calculates correlation coefficient by following command >> [r]=corrcoef(X)
and give me the result
do you know how should I revise the GUI?
0 Comments
Accepted Answer
Grzegorz Knor
on 9 Sep 2011
First you have to create *.mat file:
X = rand(10);
save Xvar X
And possible solution:
function [] = Mohammad()
M = figure('units','pixels',...
'position',[500 500 200 50],...
'menubar','none',...
'numbertitle','off',...
'name','Mohammad',...
'resize','on');
whitebg(M,'r')
set(M,'Position',[500 500 400 300])
m = uimenu('Label','&File');
uimenu(m,'Label','Open','Callback',{@fm});
uimenu(m,'Label','Quit','Callback','close',...
'Separator','on','Accelerator','Q');
function [] = fm(varargin)
% Callback for the figure menu.
[filename, pathname] = uigetfile({'*.mat', 'All MAT-Files (*.mat)';'*.*','All Files (*.*)'},'Open file');
r = load(fullfile(pathname,filename));
disp(corrcoef(r.X))
end
end
3 Comments
Grzegorz Knor
on 9 Sep 2011
You mean something like this?
function [] = Mohammad()
M = figure('units','pixels',...
'position',[500 500 200 50],...
'menubar','none',...
'numbertitle','off',...
'name','Mohammad',...
'resize','on');
whitebg(M,'r')
set(M,'Position',[500 500 400 300])
m = uimenu('Label','&File');
uimenu(m,'Label','Open','Callback',{@fm});
uimenu(m,'Label','Quit','Callback','close',...
'Separator','on','Accelerator','Q');
h = uicontrol('Style','text','Units','normalized','Position',[.0 .25 1 .5],'BackGroundColor','r');
function [] = fm(varargin)
% Callback for the figure menu.
[filename, pathname] = uigetfile({'*.mat', 'All MAT-Files (*.mat)';'*.*','All Files (*.*)'},'Open file');
r = load(fullfile(pathname,filename));
set(h,'String',num2str(corrcoef(r.X)),'FontSize',5)
end
end
More Answers (1)
Grzegorz Knor
on 9 Sep 2011
You mean button?:)
function [] = Mohammad()
M = figure('units','pixels',...
'position',[500 500 200 50],...
'menubar','none',...
'numbertitle','off',...
'name','Mohammad',...
'resize','on');
whitebg(M,'r')
set(M,'Position',[500 500 400 300])
m = uimenu('Label','&File');
uimenu(m,'Label','Open','Callback',{@fm});
uimenu(m,'Label','Quit','Callback','close',...
'Separator','on','Accelerator','Q');
h = uicontrol('Style','pushbutton','Units','normalized','Position',[.4 .45 .2 .1],'String','CC','Callback',@fm);
function [] = fm(varargin)
% Callback for the figure menu.
[filename, pathname] = uigetfile({'*.mat', 'All MAT-Files (*.mat)';'*.*','All Files (*.*)'},'Open file');
r = load(fullfile(pathname,filename));
disp(corrcoef(r.X))
end
end
I recommend you familiarize yourself with these examples:
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!