Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
??? Undefined function or variable "data".

Subject: ??? Undefined function or variable "data".

From: Norberto Barroca

Date: 29 Sep, 2010 16:21:05

Message: 1 of 4

When I run this GUI file I got this error:
??? Undefined function or variable "data".

Error in ==> TR1000GUI>pushbutton1_Callback at 115
        DataNode(min:max,Column)=data(:,2);

Error in ==> gui_mainfcn at 96
        feval(varargin{:});

Error in ==> TR1000GUI at 42
    gui_mainfcn(gui_State, varargin{:});

Error in ==>
@(hObject,eventdata)TR1000GUI('pushbutton1_Callback',hObject,eventdata,guidata(hObject))

 ??? Error while evaluating uicontrol Callback

I want to rear several csv files and then put them in the DataNode Vector, I f I run a m file I don't have any problem however if I use a GUI file I can't run my code.

function varargout = TR1000GUI(varargin)
% TR1000GUI M-file for TR1000GUI.fig
% TR1000GUI, by itself, creates a new TR1000GUI or raises the existing
% singleton*.
%
% H = TR1000GUI returns the handle to a new TR1000GUI or the handle to
% the existing singleton*.
%
% TR1000GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TR1000GUI.M with the given input arguments.
%
% TR1000GUI('Property','Value',...) creates a new TR1000GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before TR1000GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to TR1000GUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help TR1000GUI

% Last Modified by GUIDE v2.5 29-Sep-2010 16:19:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
                   'gui_Singleton', gui_Singleton, ...
                   'gui_OpeningFcn', @TR1000GUI_OpeningFcn, ...
                   'gui_OutputFcn', @TR1000GUI_OutputFcn, ...
                   'gui_LayoutFcn', [] , ...
                   'gui_Callback', []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before TR1000GUI is made visible.
function TR1000GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to TR1000GUI (see VARARGIN)

% Choose default command line output for TR1000GUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes TR1000GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = TR1000GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
clear
Max_MsgInterArrival=10;
NumberSeeds=5;%If you change the number of seeds you need to change this code
NumberNodes=11;


% Example
%
% Number Node Values for 5 seeds
%
% 0 1 2 3 4 5 6
% 0 1 2 3 4 5 6
% 0 1 2 3 4 5 6
% 0 1 2 3 4 5 6
% 0 1 2 3 4 5 6
% 0 1 2 3 4 5 6
% 0 1 2 3 4 5 6
% 0 1 2 3 4 5 6
% 0 1 2 3 4 5 6
% 0 1 2 3 4 5 6

min=1;
max=10;
Node=0;
cont=1;
Column=2;

for i=1:NumberSeeds*NumberNodes
    string=sprintf('TR1000-%d.csv',i);
    importfile(string);
      
    if(cont<=NumberSeeds)
        %data (line, column)
        DataNode(min:max,Column)=data(:,2);
        DataNode(min:max,1)=Node;
        Column=Column+1;
        cont=cont+1;
    end
   
    if(cont==NumberSeeds+1)
        cont=1;
        Node=Node+1;
        min=min+10;
        max=max+10;
        Column=2;
    end
end

Subject: ??? Undefined function or variable "data".

From: Steven_Lord

Date: 29 Sep, 2010 16:31:26

Message: 2 of 4



"Norberto Barroca" <norberto.barroca@hotmail.com> wrote in message
news:i7vp1h$k6u$1@fred.mathworks.com...
> When I run this GUI file I got this error:
> ??? Undefined function or variable "data".

*snip*

> % --- Executes on button press in pushbutton1.
> function pushbutton1_Callback(hObject, eventdata, handles)
> % hObject handle to pushbutton1 (see GCBO)
> % eventdata reserved - to be defined in a future version of MATLAB
> % handles structure with handles and user data (see GUIDATA)
> clc
> clear
> Max_MsgInterArrival=10;
> NumberSeeds=5;%If you change the number of seeds you need to change this
> code
> NumberNodes=11;
>
>
> % Example
> % % Number Node Values for 5 seeds % % 0 1 2 3
> 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
>
> min=1;
> max=10;
> Node=0;
> cont=1;
> Column=2;
>
> for i=1:NumberSeeds*NumberNodes
> string=sprintf('TR1000-%d.csv',i);
> importfile(string);
> if(cont<=NumberSeeds)
> %data (line, column)
> DataNode(min:max,Column)=data(:,2);

Nowhere in this function do you assign a value to the variable data so
MATLAB (correctly) errors saying that it doesn't know what you mean when you
try to use a variable named data on this line.

Remember that functions operate in their own workspaces; they do NOT
normally have access to data in other function workspaces or in the base
workspace. You may, if you read the data in a different callback, be
interested in question 5.16 in the newsgroup FAQ, which lists two
discussions in the documentation of how to share information between GUI
callback functions.

*snip*

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: ??? Undefined function or variable "data".

From: Sean

Date: 29 Sep, 2010 16:33:22

Message: 3 of 4

"Norberto Barroca" <norberto.barroca@hotmail.com> wrote in message <i7vp1h$k6u$1@fred.mathworks.com>...
> When I run this GUI file I got this error:
> ??? Undefined function or variable "data".
>
> Error in ==> TR1000GUI>pushbutton1_Callback at 115
> DataNode(min:max,Column)=data(:,2);
>
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
>
> Error in ==> TR1000GUI at 42
> gui_mainfcn(gui_State, varargin{:});
>
> Error in ==>
> @(hObject,eventdata)TR1000GUI('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
>
> ??? Error while evaluating uicontrol Callback
>
> I want to rear several csv files and then put them in the DataNode Vector, I f I run a m file I don't have any problem however if I use a GUI file I can't run my code.
>
> function varargout = TR1000GUI(varargin)
> % TR1000GUI M-file for TR1000GUI.fig
> % TR1000GUI, by itself, creates a new TR1000GUI or raises the existing
> % singleton*.
> %
> % H = TR1000GUI returns the handle to a new TR1000GUI or the handle to
> % the existing singleton*.
> %
> % TR1000GUI('CALLBACK',hObject,eventData,handles,...) calls the local
> % function named CALLBACK in TR1000GUI.M with the given input arguments.
> %
> % TR1000GUI('Property','Value',...) creates a new TR1000GUI or raises the
> % existing singleton*. Starting from the left, property value pairs are
> % applied to the GUI before TR1000GUI_OpeningFcn gets called. An
> % unrecognized property name or invalid value makes property application
> % stop. All inputs are passed to TR1000GUI_OpeningFcn via varargin.
> %
> % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
> % instance to run (singleton)".
> %
> % See also: GUIDE, GUIDATA, GUIHANDLES
>
> % Edit the above text to modify the response to help TR1000GUI
>
> % Last Modified by GUIDE v2.5 29-Sep-2010 16:19:24
>
> % Begin initialization code - DO NOT EDIT
> gui_Singleton = 1;
> gui_State = struct('gui_Name', mfilename, ...
> 'gui_Singleton', gui_Singleton, ...
> 'gui_OpeningFcn', @TR1000GUI_OpeningFcn, ...
> 'gui_OutputFcn', @TR1000GUI_OutputFcn, ...
> 'gui_LayoutFcn', [] , ...
> 'gui_Callback', []);
> if nargin && ischar(varargin{1})
> gui_State.gui_Callback = str2func(varargin{1});
> end
>
> if nargout
> [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
> else
> gui_mainfcn(gui_State, varargin{:});
> end
> % End initialization code - DO NOT EDIT
>
>
> % --- Executes just before TR1000GUI is made visible.
> function TR1000GUI_OpeningFcn(hObject, eventdata, handles, varargin)
> % This function has no output args, see OutputFcn.
> % hObject handle to figure
> % eventdata reserved - to be defined in a future version of MATLAB
> % handles structure with handles and user data (see GUIDATA)
> % varargin command line arguments to TR1000GUI (see VARARGIN)
>
> % Choose default command line output for TR1000GUI
> handles.output = hObject;
>
> % Update handles structure
> guidata(hObject, handles);
>
> % UIWAIT makes TR1000GUI wait for user response (see UIRESUME)
> % uiwait(handles.figure1);
>
>
> % --- Outputs from this function are returned to the command line.
> function varargout = TR1000GUI_OutputFcn(hObject, eventdata, handles)
> % varargout cell array for returning output args (see VARARGOUT);
> % hObject handle to figure
> % eventdata reserved - to be defined in a future version of MATLAB
> % handles structure with handles and user data (see GUIDATA)
>
> % Get default command line output from handles structure
> varargout{1} = handles.output;
>
>
> % --- Executes on button press in pushbutton1.
> function pushbutton1_Callback(hObject, eventdata, handles)
> % hObject handle to pushbutton1 (see GCBO)
> % eventdata reserved - to be defined in a future version of MATLAB
> % handles structure with handles and user data (see GUIDATA)
> clc
> clear
> Max_MsgInterArrival=10;
> NumberSeeds=5;%If you change the number of seeds you need to change this code
> NumberNodes=11;
>
>
> % Example
> %
> % Number Node Values for 5 seeds
> %
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
> % 0 1 2 3 4 5 6
>
> min=1;
> max=10;
> Node=0;
> cont=1;
> Column=2;
>
> for i=1:NumberSeeds*NumberNodes
> string=sprintf('TR1000-%d.csv',i);
> importfile(string);
>
> if(cont<=NumberSeeds)
> %data (line, column)
> DataNode(min:max,Column)=data(:,2);
> DataNode(min:max,1)=Node;
> Column=Column+1;
> cont=cont+1;
> end
>
> if(cont==NumberSeeds+1)
> cont=1;
> Node=Node+1;
> min=min+10;
> max=max+10;
> Column=2;
> end
> end

It means your variable 'data' has not been defined. Scrolling through your code real quick it doesn't look like it's been defined anywhere. If it's defined in the work space it won't be available to the GUI. Use setappdata, getappdata to pass variables between callbacks.

Subject: ??? Undefined function or variable "data".

From: Walter Roberson

Date: 29 Sep, 2010 17:34:02

Message: 4 of 4

On 10-09-29 11:31 AM, Steven_Lord wrote:
>
>
> "Norberto Barroca" <norberto.barroca@hotmail.com> wrote in message
> news:i7vp1h$k6u$1@fred.mathworks.com...


>> for i=1:NumberSeeds*NumberNodes
>> string=sprintf('TR1000-%d.csv',i);
>> importfile(string);
>> if(cont<=NumberSeeds)
>> %data (line, column)
>> DataNode(min:max,Column)=data(:,2);

> Nowhere in this function do you assign a value to the variable data so
> MATLAB (correctly) errors saying that it doesn't know what you mean when
> you try to use a variable named data on this line.

Under some circumstances, importfile() will create a variable named "data".
The example in the documentation for "Using the import wizard" hints that this
variable would be created in the base workspace rather than in the callers
workspace.

It would probably make more sense to use xlsread() or dlmread(), but whatever.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us