From: ClauDe De on
Hallo everyone,

ok, I hope I can explain my problem properly...

Within a loop, I would like to save my variables under a special filename which
I want to take out of "B". "B" contains Instrumentnumbers (f.ex.: 2342, 2355, 16019, ... ) Here: size(B) = 1 58

The loop loads a netcdf-file and the variables are created.
Now I would like to save them in a MAT-file named after the
Instrumentnumber.
Something like: save Instr_2342 var1 var2 var3
end of loop

But I got no idea how to let it take the next number out of "B" with every loop and save it under that name.

I have the feeling that this is quite simple, but I got stuck there...

Thanks for your help and comments in advance!!! I really appreciate it!
From: Joshua Arnott on
"ClauDe De" <acerxenite(a)yahoo.de> wrote in message <hsbbp0$qlt$1(a)fred.mathworks.com>...
> Hallo everyone,
>
> ok, I hope I can explain my problem properly...
>
> Within a loop, I would like to save my variables under a special filename which
> I want to take out of "B". "B" contains Instrumentnumbers (f.ex.: 2342, 2355, 16019, ... ) Here: size(B) = 1 58
>
> The loop loads a netcdf-file and the variables are created.
> Now I would like to save them in a MAT-file named after the
> Instrumentnumber.
> Something like: save Instr_2342 var1 var2 var3
> end of loop
>
> But I got no idea how to let it take the next number out of "B" with every loop and save it under that name.
>
> I have the feeling that this is quite simple, but I got stuck there...
>
> Thanks for your help and comments in advance!!! I really appreciate it!

Assuming your B variable is a cell array:

for k = 1:length(B)
% do some processing
save(sprintf('%s',B{k}),'var1','var2','etc');
end
From: ClauDe on
> Assuming your B variable is a cell array:
>
> for k = 1:length(B)
> % do some processing
> save(sprintf('%s',B{k}),'var1','var2','etc');
> end


Thanks for the quick response!!!!!

Unfortunately, B is no cell-array...

my attempt: turned it into a cell-array (num2cell)
But it's not working either...
Got this error:
??? Error using ==> save
Unable to write file : Invalid argument.

mmh... any clue?!

Thanks!!
From: ClauDe on
> > Assuming your B variable is a cell array:
> >
> > for k = 1:length(B)
> > % do some processing
> > save(sprintf('%s',B{k}),'var1','var2','etc');
> > end

Oh, and when I run this with k = 1
The created MAT-File is called B{k}.mat ...
From: ClauDe on

> Oh, and when I run this with k = 1
> The created MAT-File is called B{k}.mat ...

ups... within my testing"rage", I wrote 'B{k}'... of course the name is B{k} then...
without apostrophe it's still the array- and/or argument error...
 |  Next  |  Last
Pages: 1 2
Prev: Matlab and FaroArm developer
Next: explain please