Re: Creating a variable variable name o_O
- From: "Andy Eisenberg" <theorigamist@xxxxxxxxx>
- Date: Wed, 15 Jul 2009 19:32:02 +0000 (UTC)
"Andy Eisenberg" <theorigamist@xxxxxxxxx> wrote in message <h3l9s7$vk$1@xxxxxxxxxxxxxxxxxx>...
"Judy " <sauwen.jl@xxxxxxxxx> wrote in message <h3l8dd$ksj$1@xxxxxxxxxxxxxxxxxx>...
Hi everyone,
I am trying to make a loop to make small chunks of an array instead of a single large array (memory problems).
I am thinking to renaming each chunk name#..so:
Name1
Name2
Name3
so on..
What is the best way to do this?
I tried:
for cnt=1:n,
['Name' cnt]=array
end
However that gives me an error.
??? Error: An array for multiple LHS assignment cannot contain character string.
Should ['Name' cnt] be changed to something else other than a string? If so, in what form?
Thanks for any advice.
Try this:
array=rand(1,10);
for cnt=1:10
eval(sprintf('Name%d=%d',i,array(i)));
end
Whoops. Some sloppy errors here. Try this:
array=rand(1,10);
for i=1:10
eval(sprintf('Name%d=%d;',i,array(i)))
end
% Changes: before I left 'cnt' as the increment in the for loop, even though I
% referenced it as i.
% Also, make sure you have the semicolon inside the regular expression in sprintf.
% Otherwise a semicolon at the end of the line is not enough to prevent the
% variables displaying to the command line.
.
- References:
- Creating a variable variable name o_O
- From: Judy
- Re: Creating a variable variable name o_O
- From: Andy Eisenberg
- Creating a variable variable name o_O
- Prev by Date: Re: repetitive counter (GUI)
- Next by Date: Re: quick ? using quad with anonymous function
- Previous by thread: Re: Creating a variable variable name o_O
- Next by thread: Re: Creating a variable variable name o_O
- Index(es):
Relevant Pages
|