how to use of GUI?

2 views (last 30 days)
Niki
Niki on 9 Sep 2011
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?

Accepted Answer

Grzegorz Knor
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
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
Niki
Niki on 9 Sep 2011
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

Sign in to comment.

More Answers (1)

Grzegorz Knor
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:
  1 Comment
Niki
Niki on 9 Sep 2011
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

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!