how to use of GUI?

2 次查看(过去 30 天)
Niki
Niki 2011-9-9
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?

采纳的回答

Grzegorz Knor
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
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
Niki
Niki 2011-9-9
No, I wanted to put a bottom on the window for example "CC",
then I load the data by "open" and when I push the "CC" it calculates the correlation coefficient

请先登录,再进行评论。

更多回答(1 个)

Grzegorz Knor
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:
  1 个评论
Niki
Niki 2011-9-9
Thanks, In fact I went through all of them ,
It was not what I wanted,
Ok you put a bottom but all what I wanted was ,
using the "Open " to load the data
and program wait until I push on the bottom , then calculate it , it was all what I wanted

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by