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:
Saving figure error (invalid argument)

Subject: Saving figure error (invalid argument)

From: Nicolas

Date: 18 Apr, 2010 18:23:06

Message: 1 of 5

I've searched through the newsgroup archives for an answer to my question, and I've read through FAQ 4.12, but I still can't find a solution to my particular issue.

I'm trying to automate the saving of a figure as .fig. It is in a loop which changes the figure's filename with each iteration of the loop. Here's the relevant portion of code:

figname = sprintf('%s_%s_%s\b\b\b\b', EEG.chanlocs(currChan1).labels, EEG.chanlocs(currChan2).labels, currfile);

figname = Fz_Cz_STROOP0037

figure;

saveas(gcf, figname, 'fig');

------
Everything works beautifully until the saving.

Thanks,
Nick

Subject: Saving figure error (invalid argument)

From: ImageAnalyst

Date: 18 Apr, 2010 20:16:29

Message: 2 of 5

What's the problem? Didn't it add the .fig extension? Try
putting .fig into the end of your format string in your printf(). And
what's the point of the 4 \b's?

Subject: Saving figure error (invalid argument)

From: Nicolas

Date: 19 Apr, 2010 00:07:04

Message: 3 of 5

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <7b25bb23-61c2-46d3-9d26-e99b8bd23d61@c1g2000vbc.googlegroups.com>...
> What's the problem? Didn't it add the .fig extension? Try
> putting .fig into the end of your format string in your printf(). And
> what's the point of the 4 \b's?

I put the \b's in there because I only needed a portion of the string (it is used in its full form in other functions of the script). I tried your idea, but it gave me a similar response as my original:

??? Error using ==> save
Unable to write file Fz_Cz_STROOP0037.fig: Invalid argument.

Error in ==> hgsave at 239
save(filename, 'hgS_070000',varargin{save_args:end});

Error in ==> general\private\saveasfig at 7
hgsave( h, name );

Error in ==> saveas at 130
    feval( ['saveas' format], h, name )

Error in ==> coherence at 59
            saveas(gcf, figname);
----------------
Your thoughts?

Thanks,
Nick

Subject: Saving figure error (invalid argument)

From: ImageAnalyst

Date: 19 Apr, 2010 00:37:59

Message: 4 of 5

Nick:
Does it work if you hard code the name Fz_Cz_STROOP0037.fig in there?
Maybe that weird \b stuff is messing it up - you don't see it but it's
there as hidden characters. Why don't you just use regular indexing
like currfile(1:end-4) to get all but the last 4 chars, instead of the
full currfile and 4 backspaces (which is kind of weird - I've not seen
that before)?

Subject: Saving figure error (invalid argument)

From: Nicolas

Date: 19 Apr, 2010 00:55:08

Message: 5 of 5

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <280e5ef9-235d-4640-89ca-0b2f01572fd8@i12g2000vba.googlegroups.com>...
> Nick:
> Does it work if you hard code the name Fz_Cz_STROOP0037.fig in there?
> Maybe that weird \b stuff is messing it up - you don't see it but it's
> there as hidden characters. Why don't you just use regular indexing
> like currfile(1:end-4) to get all but the last 4 chars, instead of the
> full currfile and 4 backspaces (which is kind of weird - I've not seen
> that before)?

Ah ha! Worked wonderfully. Thanks for the tip. It must have been the \b's messing it up.

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