how to use of GUI?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Grzegorz Knor
2011-9-9
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 个评论
Grzegorz Knor
2011-9-9
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
更多回答(1 个)
Grzegorz Knor
2011-9-9
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:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!