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:
Invalid filename when saving diagram. But why?

Subject: Invalid filename when saving diagram. But why?

From: Ulrik Nash

Date: 4 Nov, 2011 19:17:10

Message: 1 of 9

Hi,

What am I doing wrong here?

I have the following rather long name (which is created from a list of variable values):

diagram_name =
'BUYERS_SCATTER_INDUSTRY_PERIOD_100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000'

and I wish to save a diagram using the following:

saveas(gcf,diagram_name,'tiff')

but I get the error message:

"Invalid filename."

Subject: Invalid filename when saving diagram. But why?

From: ImageAnalyst

Date: 4 Nov, 2011 20:04:28

Message: 2 of 9

On Nov 4, 3:17 pm, "Ulrik Nash" <u...@sam.sdu.dk> wrote:
> Hi,
>
> What am I doing wrong here?
>
> I have the following rather long name (which is created from a list of variable values):
>
> diagram_name =
> 'BUYERS_SCATTER_INDUSTRY_PERIOD_100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000'
>
> and I wish to save a diagram using the following:
>
> saveas(gcf,diagram_name,'tiff')
>
> but I get the error message:
>
> "Invalid filename."

------------------------------------------------------------------
Copied and pasted your code and it ran just fine with R2011a. Saved
the figure just fine. Copy the exact error message from the command
window, not just some paraphrased thing like you did so far.

Subject: Invalid filename when saving diagram. But why?

From: Ulrik Nash

Date: 4 Nov, 2011 21:07:27

Message: 3 of 9


> Copied and pasted your code and it ran just fine with R2011a. Saved
> the figure just fine. Copy the exact error message from the command
> window, not just some paraphrased thing like you did so far.
____________

Here is the error message:

??? Error using ==> saveas at 82
Invalid filename.


The complete code is:
diagram_extention_name =
columns = [1];
for i=1:numel(columns)
scatter(mean_ROI_buyer((num_lables + 1):(num_agents + num_lables),columns(i)), var_ROI_period_buyer((num_lables + 1):(num_agents + num_lables),columns(i)),5,'k','filled');
xlabel('Mean Return (Buyers)')
ylabel('Variance of Returns (Buyers)')
grid on
end
diagram_type = {'SCATTER'};
population_level = {'INDUSTRY'};
unit_level = {'PERIOD'};
agents = {'BUYERS'};
diagram_subject = {'Risk_Return'};
diagram_name = strcat(diagram_subject,'_',agents,'_',diagram_type,'_',population_level,'_',unit_level,'_',diagram_extention_name)

%% Creates 'Risk_Return_BUYERS_SCATTER_INDUSTRY_PERIOD_100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000'

saveas(gcf,diagram_name,'tiff')

Subject: Invalid filename when saving diagram. But why?

From: Ulrik Nash

Date: 4 Nov, 2011 21:12:29

Message: 4 of 9

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j91k6f$idj$1@newscl01ah.mathworks.com>...
>
> > Copied and pasted your code and it ran just fine with R2011a. Saved
> > the figure just fine. Copy the exact error message from the command
> > window, not just some paraphrased thing like you did so far.
> ____________
>
> Here is the error message:
>
> ??? Error using ==> saveas at 82
> Invalid filename.
>
>
> The complete code is:
> diagram_extention_name =
> columns = [1];
> for i=1:numel(columns)
> scatter(mean_ROI_buyer((num_lables + 1):(num_agents + num_lables),columns(i)), var_ROI_period_buyer((num_lables + 1):(num_agents + num_lables),columns(i)),5,'k','filled');
> xlabel('Mean Return (Buyers)')
> ylabel('Variance of Returns (Buyers)')
> grid on
> end
> diagram_type = {'SCATTER'};
> population_level = {'INDUSTRY'};
> unit_level = {'PERIOD'};
> agents = {'BUYERS'};
> diagram_subject = {'Risk_Return'};
> diagram_name = strcat(diagram_subject,'_',agents,'_',diagram_type,'_',population_level,'_',unit_level,'_',diagram_extention_name)
>
> %% Creates 'Risk_Return_BUYERS_SCATTER_INDUSTRY_PERIOD_100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000'
>
> saveas(gcf,diagram_name,'tiff')



Sorry,

diagram_extention_name = '_100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000'

Subject: Invalid filename when saving diagram. But why?

From: Ulrik Nash

Date: 4 Nov, 2011 21:36:14

Message: 5 of 9

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j91kft$j7s$1@newscl01ah.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j91k6f$idj$1@newscl01ah.mathworks.com>...
> >
> > > Copied and pasted your code and it ran just fine with R2011a. Saved
> > > the figure just fine. Copy the exact error message from the command
> > > window, not just some paraphrased thing like you did so far.
> > ____________
> >


Perhaps the problem is that

diagram_extention_name =

100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000

that is, there are no ' ', as I wrongly stated before... Does this make a difference?

Subject: Invalid filename when saving diagram. But why?

From: Ulrik Nash

Date: 4 Nov, 2011 22:21:10

Message: 6 of 9

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j91lse$nfn$1@newscl01ah.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j91kft$j7s$1@newscl01ah.mathworks.com>...
> > "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j91k6f$idj$1@newscl01ah.mathworks.com>...
> > >
> > > > Copied and pasted your code and it ran just fine with R2011a. Saved
> > > > the figure just fine. Copy the exact error message from the command
> > > > window, not just some paraphrased thing like you did so far.
> > > ____________
> > >
>
>
> Perhaps the problem is that
>
> diagram_extention_name =
>
> 100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000
>
> that is, there are no ' ', as I wrongly stated before... Does this make a difference?


This is really strange. When I simply replace

saveas(gcf,diagram_name,'tiff')

with

saveas(gcf,'Risk_Return_BUYERS_SCATTER_INDUSTRY_PERIOD_100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000','tiff')

things work fine!

The strange thing is that

diagram_name =

'Risk_Return_BUYERS_SCATTER_INDUSTRY_PERIOD_100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000'

I am sure there is a simple explanation. Can anyone figure it out?

Subject: Invalid filename when saving diagram. But why?

From: Ulrik Nash

Date: 5 Nov, 2011 00:27:13

Message: 7 of 9

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j91ogm$21f$1@newscl01ah.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j91lse$nfn$1@newscl01ah.mathworks.com>...
> > "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j91kft$j7s$1@newscl01ah.mathworks.com>...
> > > "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j91k6f$idj$1@newscl01ah.mathworks.com>...
> > > >
> > > > > Copied and pasted your code and it ran just fine with R2011a. Saved
> > > > > the figure just fine. Copy the exact error message from the command
> > > > > window, not just some paraphrased thing like you did so far.
> > > > ____________
> > > >
> >
> >
> > Perhaps the problem is that
> >
> > diagram_extention_name =
> >
> > 100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000
> >
> > that is, there are no ' ', as I wrongly stated before... Does this make a difference?
>
>
> This is really strange. When I simply replace
>
> saveas(gcf,diagram_name,'tiff')
>
> with
>
> saveas(gcf,'Risk_Return_BUYERS_SCATTER_INDUSTRY_PERIOD_100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000','tiff')
>
> things work fine!
>
> The strange thing is that
>
> diagram_name =
>
> 'Risk_Return_BUYERS_SCATTER_INDUSTRY_PERIOD_100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000'
>
> I am sure there is a simple explanation. Can anyone figure it out?





Issue has been resolved.....

Subject: Invalid filename when saving diagram. But why?

From: Steven_Lord

Date: 7 Nov, 2011 15:24:47

Message: 8 of 9



"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message
news:j91k6f$idj$1@newscl01ah.mathworks.com...
>
>> Copied and pasted your code and it ran just fine with R2011a. Saved
>> the figure just fine. Copy the exact error message from the command
>> window, not just some paraphrased thing like you did so far.
> ____________
>
> Here is the error message:
>
> ??? Error using ==> saveas at 82
> Invalid filename.
>
>
> The complete code is:
> diagram_extention_name =
> columns = [1];
> for i=1:numel(columns)
> scatter(mean_ROI_buyer((num_lables + 1):(num_agents +
> num_lables),columns(i)), var_ROI_period_buyer((num_lables + 1):(num_agents
> + num_lables),columns(i)),5,'k','filled');
> xlabel('Mean Return (Buyers)')
> ylabel('Variance of Returns (Buyers)')
> grid on
> end
> diagram_type = {'SCATTER'};
> population_level = {'INDUSTRY'};
> unit_level = {'PERIOD'};
> agents = {'BUYERS'};
> diagram_subject = {'Risk_Return'};
> diagram_name =
> strcat(diagram_subject,'_',agents,'_',diagram_type,'_',population_level,'_',unit_level,'_',diagram_extention_name)

When created like this, diagram_name is a cell array containing one char
array. SAVEAS expects the filename input to be a char array, not a cell
array. Extract the contents of the cell array and pass _that_ into SAVEAS as
your name.

dn = diagram_name{1}

> %% Creates
> 'Risk_Return_BUYERS_SCATTER_INDUSTRY_PERIOD_100_10_1_50_50_0_05_1_10000_1000_1000_1000_1000_900_500_50_50_1000_1000'
>
> saveas(gcf,diagram_name,'tiff')

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Invalid filename when saving diagram. But why?

From: ImageAnalyst

Date: 7 Nov, 2011 22:02:42

Message: 9 of 9

Yeah, I think he'd be best off converting this line

diagram_name =
strcat(diagram_subject,'_',agents,'_',diagram_type,'_',population_level,'_',unit_level,'_',diagram_extention_name)

into a string with sprintf().

Tags for 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