function or variable not found (uicontrol callback)

Hi guys...
I know you get this very often but I've been looking at the other threads and none has helped me solve my issue.
So here's my code so far:
Main workspace
clear all
close all
clc
global A RMS ERH ERZ
%Loading data
A=load('CATPOPOCATEPETL.dat');
cata='CATPOPOCATEPETL.dat';
RMS=A(:,10);
ERH=A(:,11);
ERZ=A(:,12);
YR=A(:,3);
MNTH=A(:,4);
DYS=A(:,5);
%Removing RMS >= 3
w=RMS(:)>=3.0;
w=find(w);
[RMS,ps]=removerows(RMS,w);
%Removing ERZ >= 10[km]
w1=ERZ(:)>=10;
w1=find(w1);
[ERZ,ps]=removerows(ERZ,w1);
%Removing ERH >= 10[km]
w2=ERH(:)>=10;
w2=find(w2);
[ERH,ps]=removerows(ERH,w2);
%Getting means of location errors
meanRMS=mean(RMS);
meanERH=mean(ERH);
meanERZ=mean(ERZ);
choice = questdlg('Would you like to remove events?', ...
'Remove Events','Yes!','Nope','Yes!');
% Switch remove
switch choice
case 'Yes!'
byerows(0)
case 'Nope'
end
And in the other .mat file (byerows.mat) I have:
function byerows(select)
global A RMS ERH ERZ
maxRMS=0.5;
maxERH=2.0;
maxERZ=2.0;
switch select
case 0
figure()
axis 'off'
tmaxRMS=uicontrol('BackGroundColor','r','Style','edit',...
'FontSize',25,...
'Position',[.45 .81 .17 .1],...
'Units','normalized','String',num2str(maxRMS));
txtRMS=text(...
'Color',[0 0 0 ],...
'EraseMode','normal',...
'Position',[0 .92],...
'Rotation',0 ,...
'FontSize',25 ,...
'FontWeight','bold',...
'String','Max(RMS) ');
tmaxERH=uicontrol('BackGroundColor','y','Style','edit',...
'FontSize',25,...
'Position',[.45 .57 .17 .1],...
'Units','normalized','String',num2str(maxERH));
txtERH=text(...
'Color',[0 0 0 ],...
'EraseMode','normal',...
'Position',[0 .62],...
'Rotation',0 ,...
'FontSize',25 ,...
'FontWeight','bold',...
'String','Max(ERH) ');
tmaxERZ=uicontrol('BackGroundColor','y','Style','edit',...
'FontSize',25,...
'Position',[.45 .32 .17 .1],...
'Units','normalized','String',num2str(maxERZ));
txtERZ=text(...
'Color',[0 0 0 ],...
'EraseMode','normal',...
'Position',[0 .32],...
'Rotation',0 ,...
'FontSize',25 ,...
'FontWeight','bold',...
'String','Max(ERH) ');
OKbutton=uicontrol('BackGroundColor','y','Style','Pushbutton',...
'Position',[.80 .05 .15 .12 ],...
'Units','normalized','String','OK',...
'CallBack','maxRMS=str2num(get(tmaxRMS,''String'')); set(tmaxRMS,''String'',num2str(maxRMS)),maxERH=str2num(get(tmaxERH,''String'')); set(tmaxERH,''String'',num2str(maxERH)),maxERZ=str2num(get(tmaxERZ,''String'')); set(tmaxERZ,''String'',num2str(maxERZ)),byerows(1)');
CANCELbutton=uicontrol('BackGroundColor','y','Style','Pushbutton',...
'Position',[.50 .05 .15 .12 ],...
'Units','normalized','Callback','byerows(2)','String','Cancel');
case 1 % Byerows
m=RMS(:)>maxRMS;
m=find(m);
[M1,ps]=removerows(A,m);
ERH1=M1(:,11);
mh=ERH1(:)>2;
mh=find(mh);
[M2,ps1]=removerows(M1,mh);
ERZ1=M2(:,12);
mz=ERZ1(:)>2;
mz=find(mz);
[M3,ps2]=removerows(M2,mz);
dlmwrite('NEWCAT.dat', M3, '\t')
close
h=msgbox('The file "NEWCAT.dat" was created','Output File','warn');
return
case 2 % Cancel
close
end
Although it looks good to me it gives me the error:
??? Undefined function or variable 'tmaxRMS'.
??? Error while evaluating uicontrol Callback
I know my programming is neither clean nor fancy but I hope you can read the code and help me out...
Thanks a lot
Ricky

回答 (1 件)

Jan
Jan 2013 年 9 月 12 日

0 投票

You define this callback as a string:
OKbutton = uicontrol( ...
...
'CallBack', 'maxRMS=str2num(get(tmaxRMS,''String'')' ...
But strings in callbacks are evaluated in the base workspace (the command window so to speak). But there the variable tmaxRMS is not known. In addition assigning maxRMS in the base workspace is not a good idea also, because such remote controlled creations of variables confuse the user and impede a debugging.
It is much better to use function handles as callbacks and store the results of calculations e.g. in the handles struct using the command guidata. Further explanations can be found when you search for "share data gui" in this forum.

カテゴリ

ヘルプ センター および File ExchangeFunction Creation についてさらに検索

質問済み:

2013 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by