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:
load & importdata functions in a GUI

Subject: load & importdata functions in a GUI

From: Paolo Giai Miniet

Date: 26 May, 2004 15:41:37

Message: 1 of 3

Hi fokls,

I've been writing a GUI in which I have to manipulate some data contained in
an ASCII .txt file.

I've written the snipped code below in the main .m file tied to the main
window of the porgram. But there is something wrong in the way I treat the
load or importdat functions I think...Here you are the two line code I'm
talking about:

%I get the file name from an edit box
filename=get(handles.load_par_file, 'string');

%the data are loaded in the matrix 'data'
data=importdata(filename)

while the first line work correctly the second line gives me an error which
looks like this:


*****
??? Error using ==> exist
Function 'exist' is not defined for values of class 'cell'.

Error in ==> D:\MATLAB6p5\toolbox\matlab\iofun\importdata.m
On line 89 ==> if exist(FileName) ~= 2

Error in ==> D:\MATLAB6p5\work\Tesi1.m (load_param_button_Callback)
On line 144 ==> data=importdata(filename)

Error in ==> D:\MATLAB6p5\toolbox\matlab\uitools\gui_mainfcn.m
On line 66 ==> feval(varargin{:});

Error in ==> D:\MATLAB6p5\work\Tesi1.m
On line 42 ==> gui_mainfcn(gui_State, varargin{:});

??? Error using ==> waitfor
Error while evaluating uicontrol Callback.
*****


While using the load function, which should gives the same results in this
case, the error message s:

*****
?? Error using ==> load
Argument must contain a string.

Error in ==> D:\MATLAB6p5\work\Tesi1.m (load_param_button_Callback)
On line 144 ==> data=load(filename)

Error in ==> D:\MATLAB6p5\toolbox\matlab\uitools\gui_mainfcn.m
On line 66 ==> feval(varargin{:});

Error in ==> D:\MATLAB6p5\work\Tesi1.m
On line 42 ==> gui_mainfcn(gui_State, varargin{:});

??? Error using ==> waitfor
Error while evaluating uicontrol Callback.

******

Any idea? I know it should be something really silly but I'm wasting a lot
of time thinking over....
Thanks in advance,
    Paolo

Subject: load & importdata functions in a GUI

From: fabien

Date: 26 May, 2004 10:55:46

Message: 2 of 3

Your problem is that filename is defined for values of class 'cell'.
You have to convert it to class 'string'. Maybe like that:
There is not a direct way you have to pass by:
first :cell to mat class by using : cell2mat
second: mat to str class by using : mat2str

I'm not sure but that sould work like that.

Good luck

Fabien.

Paolo Giai Miniet wrote:
>
>
> Hi fokls,
>
> I've been writing a GUI in which I have to manipulate some data
> contained in
> an ASCII .txt file.
>
> I've written the snipped code below in the main .m file tied to the
> main
> window of the porgram. But there is something wrong in the way I
> treat the
> load or importdat functions I think...Here you are the two line
> code I'm
> talking about:
>
> %I get the file name from an edit box
> filename=get(handles.load_par_file, 'string');
>
> %the data are loaded in the matrix 'data'
> data=importdata(filename)
>
> while the first line work correctly the second line gives me an
> error which
> looks like this:
>
>
> *****
> ??? Error using ==> exist
> Function 'exist' is not defined for values of class 'cell'.
>
> Error in ==> D:\MATLAB6p5\toolbox\matlab\iofun\importdata.m
> On line 89 ==> if exist(FileName) ~= 2
>
> Error in ==> D:\MATLAB6p5\work\Tesi1.m
(load_param_button_Callback)
> On line 144 ==> data=importdata(filename)
>
> Error in ==> D:\MATLAB6p5\toolbox\matlab\uitools\gui_mainfcn.m
> On line 66 ==> feval(varargin{:});
>
> Error in ==> D:\MATLAB6p5\work\Tesi1.m
> On line 42 ==> gui_mainfcn(gui_State, varargin{:});
>
> ??? Error using ==> waitfor
> Error while evaluating uicontrol Callback.
> *****
>
>
> While using the load function, which should gives the same results
> in this
> case, the error message s:
>
> *****
> ?? Error using ==> load
> Argument must contain a string.
>
> Error in ==> D:\MATLAB6p5\work\Tesi1.m
(load_param_button_Callback)
> On line 144 ==> data=load(filename)
>
> Error in ==> D:\MATLAB6p5\toolbox\matlab\uitools\gui_mainfcn.m
> On line 66 ==> feval(varargin{:});
>
> Error in ==> D:\MATLAB6p5\work\Tesi1.m
> On line 42 ==> gui_mainfcn(gui_State, varargin{:});
>
> ??? Error using ==> waitfor
> Error while evaluating uicontrol Callback.
>
> ******
>
> Any idea? I know it should be something really silly but I'm
> wasting a lot
> of time thinking over....
> Thanks in advance,
> Paolo
>
>
>

Subject: load & importdata functions in a GUI

From: Paolo Giai Miniet

Date: 26 May, 2004 20:50:08

Message: 3 of 3

Hi Fabien,
really thanks for your answer. You're right that was the problem: just a
casting trouble. I discovered the solution for this little riddle by coding
this way:

filename=get(handles.load_par_file, 'string')
file1 = char(filename)
data=load(file1)

Thanks to the function char() it's possible to convert the cell array given
back by the get() function to a string, that is an array of characters.

Quoting from the MATLAB HELP:

char: Create character array (string) SyntaxS = char(X)
S = char(C)
S = char(t1,t2,t3...)
Description: S = char(X) converts the array X that contains positive
integers representing character codes into a MATLAB character array (the
first 127 codes are ASCII). The actual characters displayed depend on the
character set encoding for a given font. The result for any elements of X
outside the range from 0 to 65535 is not defined (and may vary from platform
to platform). Use double to convert a character array into its numeric
codes. S = char(C) when C is a cell array of strings, places each element of
C into the rows of the character array s. Use cellstr to convert back. S =
char(t1,t2,t3,..) forms the character array S containing the text strings
T1,T2,T3,... as rows, automatically padding each string with blanks to form
a valid matrix. Each text parameter, Ti, can itself be a character array.
This allows the creation of arbitrarily large character arrays. Empty
strings are significant. RemarksOrdinarily, the elements of A are integers
in the range 32:127,


Thanks again and good luck to you too :-)
    Paolo.


Fabien wrote:
> Your problem is that filename is defined for values of class 'cell'.
> You have to convert it to class 'string'. Maybe like that:
> There is not a direct way you have to pass by:
> first :cell to mat class by using : cell2mat
> second: mat to str class by using : mat2str
>
> I'm not sure but that sould work like that.
>
> Good luck
>
> Fabien.
>
> Paolo Giai Miniet wrote:
>>
>>
>> Hi fokls,
>>
>> I've been writing a GUI in which I have to manipulate some data
>> contained in
>> an ASCII .txt file.
>>
>> I've written the snipped code below in the main .m file tied to the
>> main
>> window of the porgram. But there is something wrong in the way I
>> treat the
>> load or importdat functions I think...Here you are the two line
>> code I'm
>> talking about:
>>
>> %I get the file name from an edit box
>> filename=get(handles.load_par_file, 'string');
>>
>> %the data are loaded in the matrix 'data'
>> data=importdata(filename)
>>
>> while the first line work correctly the second line gives me an
>> error which
>> looks like this:
>>
>>
>> *****
>> ??? Error using ==> exist
>> Function 'exist' is not defined for values of class 'cell'.
>>
>> Error in ==> D:\MATLAB6p5\toolbox\matlab\iofun\importdata.m
>> On line 89 ==> if exist(FileName) ~= 2
>>
>> Error in ==> D:\MATLAB6p5\work\Tesi1.m (load_param_button_Callback)
>> On line 144 ==> data=importdata(filename)
>>
>> Error in ==> D:\MATLAB6p5\toolbox\matlab\uitools\gui_mainfcn.m
>> On line 66 ==> feval(varargin{:});
>>
>> Error in ==> D:\MATLAB6p5\work\Tesi1.m
>> On line 42 ==> gui_mainfcn(gui_State, varargin{:});
>>
>> ??? Error using ==> waitfor
>> Error while evaluating uicontrol Callback.
>> *****
>>
>>
>> While using the load function, which should gives the same results
>> in this
>> case, the error message s:
>>
>> *****
>> ?? Error using ==> load
>> Argument must contain a string.
>>
>> Error in ==> D:\MATLAB6p5\work\Tesi1.m (load_param_button_Callback)
>> On line 144 ==> data=load(filename)
>>
>> Error in ==> D:\MATLAB6p5\toolbox\matlab\uitools\gui_mainfcn.m
>> On line 66 ==> feval(varargin{:});
>>
>> Error in ==> D:\MATLAB6p5\work\Tesi1.m
>> On line 42 ==> gui_mainfcn(gui_State, varargin{:});
>>
>> ??? Error using ==> waitfor
>> Error while evaluating uicontrol Callback.
>>
>> ******
>>
>> Any idea? I know it should be something really silly but I'm
>> wasting a lot
>> of time thinking over....
>> Thanks in advance,
>> Paolo

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