From: shaukat Ali on
Dear all
I am in the process of writing a program in which i need to Assign different values to a variable in every loop. Suppose i have loaded a matrices Tw1, Tw2, ............., Tw90 in the workspace and want to assign these values one by one to a variable say Tw successively in every loop in the following sample program -

for ctr=1:1:90
Tw=Tw1 (for ctr=1), Tw2 (for ctr=2), ......................., Tw90(for ctr=90)
Tx=2*Tw;
Tx1=Tx (for ctr=1), Tx2=Tx (for ctr=2), ........................., Tx90=Tx (for ctr=90)
end

Further, after processing i have to assign the matrix Tx to different variables say Tx1, Tx2, ........, Tx90 in each loop. plz help solve.
From: Walter Roberson on
shaukat Ali wrote:
> Dear all
> I am in the process of writing a program in which i need to Assign
> different values to a variable in every loop. Suppose i have loaded a
> matrices Tw1, Tw2, ............., Tw90 in the workspace and want to
> assign these values one by one to a variable say Tw successively in
> every loop in the following sample program -
>
> for ctr=1:1:90
> Tw=Tw1 (for ctr=1), Tw2 (for ctr=2), ......................., Tw90(for
> ctr=90)
> Tx=2*Tw;
> Tx1=Tx (for ctr=1), Tx2=Tx (for ctr=2), .........................,
> Tx90=Tx (for ctr=90)
> end
>
> Further, after processing i have to assign the matrix Tx to different
> variables say Tx1, Tx2, ........, Tx90 in each loop. plz help solve.

Please don't do that!

http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
From: ImageAnalyst on
Don't do it in a loop. Just string them all together on one line:

Tw = [Tw2, Tw2, Tw3, Tw4, etc., Tw89, Tw90];

You'll have to type out all 90 of them but it shouldn't' take too
long. People do this all the time, just not with 90 variables. By
the way, how did you happen to end up with 90 differently named
variables anyway? Why can't the code that created them just write to
elements of an array?

I don't understand your second question. How is that any different
than the last pseudocode statement in your for loop? And what is
"processing" - is that the entire contents of your for loop, or just
the first and second line (I'm trying to figure out your second
question)?
From: shaukat Ali on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <6c97264e-4b38-493c-ae37-e64c127acfa7(a)u26g2000yqu.googlegroups.com>...
> Don't do it in a loop. Just string them all together on one line:
>
> Tw = [Tw2, Tw2, Tw3, Tw4, etc., Tw89, Tw90];
>
> You'll have to type out all 90 of them but it shouldn't' take too
> long. People do this all the time, just not with 90 variables. By
> the way, how did you happen to end up with 90 differently named
> variables anyway? Why can't the code that created them just write to
> elements of an array?
>
> I don't understand your second question. How is that any different
> than the last pseudocode statement in your for loop? And what is
> "processing" - is that the entire contents of your for loop, or just
> the first and second line (I'm trying to figure out your second
> question)?


But using the syntax Tw = [Tw1, Tw2, Tw3, Tw4, etc., Tw89, Tw90]; Tw becomes horizontal concatenation of all the matrices. i want to assign the matrices to Tw one by one in every loop.
From: fabio freschi on
you could use cell arrays. Supposing that Tw is already stored in a cell array

Tx = cell(size(Tw));
for ctr=1:1:90
Tx{ctr}=2*Tw{ctr};
end

"shaukat Ali" <shaukat779(a)gmail.com> wrote in message <hv0it5$5gl$1(a)fred.mathworks.com>...
> ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <6c97264e-4b38-493c-ae37-e64c127acfa7(a)u26g2000yqu.googlegroups.com>...
> > Don't do it in a loop. Just string them all together on one line:
> >
> > Tw = [Tw2, Tw2, Tw3, Tw4, etc., Tw89, Tw90];
> >
> > You'll have to type out all 90 of them but it shouldn't' take too
> > long. People do this all the time, just not with 90 variables. By
> > the way, how did you happen to end up with 90 differently named
> > variables anyway? Why can't the code that created them just write to
> > elements of an array?
> >
> > I don't understand your second question. How is that any different
> > than the last pseudocode statement in your for loop? And what is
> > "processing" - is that the entire contents of your for loop, or just
> > the first and second line (I'm trying to figure out your second
> > question)?
>
>
> But using the syntax Tw = [Tw1, Tw2, Tw3, Tw4, etc., Tw89, Tw90]; Tw becomes horizontal concatenation of all the matrices. i want to assign the matrices to Tw one by one in every loop.
 | 
Pages: 1
Prev: How do you do this fast?
Next: Zooming on Pictures