Thread Subject: error on running eval and save

Subject: error on running eval and save

From: Kuo-Hsien

Date: 6 Nov, 2009 16:54:02

Message: 1 of 6

Dear all,

I stuck by my code for couple days. I come here to ask any guidance and suggestions. Please kindly point the problems and solutions out. Thanks. My purpose is to create new files contain NaNs <48x1 double> and the file names are named by date. The desired file names will be picking up from a <366x1 cell> tmp_filenames by ismember.

The error message is:
??? Error using ==> eval
Undefined function or method 'save20080101fillin' for input arguments of type 'char'.

What should I do?

----------------------------------
[tf, index] = ismember(tmp_filenames,filename_4_compare);
for n = 1:length(find(index == 0))
    fillin_filename = [tmp_filenames(n)]
    fillin_filename = cell2mat(fillin_filename)
    fillin = ones(48,1) * NaN
    eval(['save' ,fillin_filename ,'fillin -ascii'])
end
----------------------------------
index : <366x1 double>
tmp_filenames : <366x1 cell>
filename_4_compare : <10x1 cell>

Subject: error on running eval and save

From: someone

Date: 6 Nov, 2009 17:23:04

Message: 2 of 6

"Kuo-Hsien" <mchangks@hotmail.com> wrote in message <hd1kba$dvr$1@fred.mathworks.com>...
> Dear all,
>
> I stuck by my code for couple days. I come here to ask any guidance and suggestions. Please kindly point the problems and solutions out. Thanks. My purpose is to create new files contain NaNs <48x1 double> and the file names are named by date. The desired file names will be picking up from a <366x1 cell> tmp_filenames by ismember.
>
> The error message is:
> ??? Error using ==> eval
> Undefined function or method 'save20080101fillin' for input arguments of type 'char'.
>
> What should I do?
>
> ----------------------------------
> [tf, index] = ismember(tmp_filenames,filename_4_compare);
> for n = 1:length(find(index == 0))
> fillin_filename = [tmp_filenames(n)]
> fillin_filename = cell2mat(fillin_filename)
> fillin = ones(48,1) * NaN
> eval(['save' ,fillin_filename ,'fillin -ascii'])
> end
> ----------------------------------
> index : <366x1 double>
> tmp_filenames : <366x1 cell>
> filename_4_compare : <10x1 cell>

% I think you need to add some spaces after save.
% replace:
     eval(['save' ,fillin_filename ,'fillin -ascii'])
% with
     eval(['save ' ,fillin_filename ,' fillin -ascii'])

Subject: error on running eval and save

From: someone

Date: 6 Nov, 2009 17:26:10

Message: 3 of 6

"Kuo-Hsien" <mchangks@hotmail.com> wrote in message <hd1kba$dvr$1@fred.mathworks.com>...
> Dear all,
>
> I stuck by my code for couple days. I come here to ask any guidance and suggestions. Please kindly point the problems and solutions out. Thanks. My purpose is to create new files contain NaNs <48x1 double> and the file names are named by date. The desired file names will be picking up from a <366x1 cell> tmp_filenames by ismember.
>
> The error message is:
> ??? Error using ==> eval
> Undefined function or method 'save20080101fillin' for input arguments of type 'char'.
>
> What should I do?
>
> ----------------------------------
> [tf, index] = ismember(tmp_filenames,filename_4_compare);
> for n = 1:length(find(index == 0))
> fillin_filename = [tmp_filenames(n)]
> fillin_filename = cell2mat(fillin_filename)
> fillin = ones(48,1) * NaN
> eval(['save' ,fillin_filename ,'fillin -ascii'])
> end
> ----------------------------------
> index : <366x1 double>
> tmp_filenames : <366x1 cell>
> filename_4_compare : <10x1 cell>

% I think you need to add some spaces after save.
% replace:
     eval(['save' ,fillin_filename ,'fillin -ascii'])
% with
     eval(['save ' ,fillin_filename ,' fillin -ascii'])

Subject: error on running eval and save

From: Steven Lord

Date: 6 Nov, 2009 17:53:14

Message: 4 of 6


"Kuo-Hsien" <mchangks@hotmail.com> wrote in message
news:hd1kba$dvr$1@fred.mathworks.com...
> Dear all,
>
> I stuck by my code for couple days. I come here to ask any guidance and
> suggestions. Please kindly point the problems and solutions out. Thanks.
> My purpose is to create new files contain NaNs <48x1 double> and the file
> names are named by date. The desired file names will be picking up from a
> <366x1 cell> tmp_filenames by ismember.
>
> The error message is:
> ??? Error using ==> eval
> Undefined function or method 'save20080101fillin' for input arguments of
> type 'char'.
>
> What should I do?
>
> ----------------------------------
> [tf, index] = ismember(tmp_filenames,filename_4_compare);
> for n = 1:length(find(index == 0))
> fillin_filename = [tmp_filenames(n)]
> fillin_filename = cell2mat(fillin_filename)

If tmp_filenames is a cell array where each cell contains a file name, you
can replace the previous two lines with:

fillin_filename = tmp_filenames{n};

> fillin = ones(48,1) * NaN
> eval(['save' ,fillin_filename ,'fillin -ascii'])

Remove the EVAL call and use the functional form of SAVE:

save(fillin_filename, 'fillin', '-ascii');

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: error on running eval and save

From: Kuo-Hsien

Date: 8 Nov, 2009 03:59:03

Message: 5 of 6

Hi Steve, it works!! Thanks. One more question: if I like to save the files to a desired path, such as: /Users/cks/Documents/Matlab/

And, I also set a path for the desired path as: pathway = '/Users/cks/Documents/Matlab/'

How to modify the following code correctly?
eval(['save pathway/fillin_filename', 'fillin -ascii'])

Thanks Steve.

Subject: error on running eval and save

From: Steven Lord

Date: 8 Nov, 2009 23:17:59

Message: 6 of 6


"Kuo-Hsien" <mchangks@hotmail.com> wrote in message
news:hd5fm7$5sc$1@fred.mathworks.com...
> Hi Steve, it works!! Thanks. One more question: if I like to save the
> files to a desired path, such as: /Users/cks/Documents/Matlab/
>
> And, I also set a path for the desired path as: pathway =
> '/Users/cks/Documents/Matlab/'
>
> How to modify the following code correctly?
> eval(['save pathway/fillin_filename', 'fillin -ascii'])

DON'T USE EVAL IN THIS CASE.

Separate the construction of the file name (which will use some of the
string processing functions) from the SAVE call.

realfilename = [pathway filename];
% or use FULLFILE

save(realfilename, 'filln', '-ascii')

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
eval Kuo-Hsien 6 Nov, 2009 11:59:03
save Kuo-Hsien 6 Nov, 2009 11:59:03
loop Kuo-Hsien 6 Nov, 2009 11:59:03
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com