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!