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:
Automating naming of new matrices

Subject: Automating naming of new matrices

From: SG

Date: 8 Nov, 2010 18:18:03

Message: 1 of 5

%I have a 100x100 matrix:

clear

A = zeros(100, 100);

A(45:54,45:54) = 1;

%I want to create a new matrix as follows:

yt = unifrnd(0,1,1);

if yt < 0.25;
    A1 = zeros(100,100);
    A1(:,51:100) = A(:,51:100);
    A(:,51:100) = 0;
else
    A;
end

%This will be part of a much longer loop, but what I really need is to know
%how to automate the naming of the new matrix that is created - so that for
%this case A1 it is named with the letter of it's parent matrix (A), and then the
%number 1 because it is the first daughter matrix, but that if in the next
%round, yt < 0.25 the next new matrix that is created will be called A2,
%and so on. (As well, at if A1 were to create a daughter matrix as well,
%then I would like it to be named A11, A12 and so on..)

%The idea behind this is to track the lineage of the matrices

Subject: Automating naming of new matrices

From: Sean

Date: 8 Nov, 2010 18:30:25

Message: 2 of 5

"SG " <sigrdson@gmail.com> wrote in message <ib9esr$r2c$1@fred.mathworks.com>...
> %I have a 100x100 matrix:
>
> clear
>
> A = zeros(100, 100);
>
> A(45:54,45:54) = 1;
>
> %I want to create a new matrix as follows:
>
> yt = unifrnd(0,1,1);
>
> if yt < 0.25;
> A1 = zeros(100,100);
> A1(:,51:100) = A(:,51:100);
> A(:,51:100) = 0;
> else
> A;
> end
>
> %This will be part of a much longer loop, but what I really need is to know
> %how to automate the naming of the new matrix that is created - so that for
> %this case A1 it is named with the letter of it's parent matrix (A), and then the
> %number 1 because it is the first daughter matrix, but that if in the next
> %round, yt < 0.25 the next new matrix that is created will be called A2,
> %and so on. (As well, at if A1 were to create a daughter matrix as well,
> %then I would like it to be named A11, A12 and so on..)
>
> %The idea behind this is to track the lineage of the matrices

Don't do this!

Unfortunately the FAQ is down so we can't link you directly to it. I believe it was question 4.12.

Subject: Automating naming of new matrices

From: SG

Date: 8 Nov, 2010 19:07:04

Message: 3 of 5

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ib9fk1$eme$1@fred.mathworks.com>...
> "SG " <sigrdson@gmail.com> wrote in message <ib9esr$r2c$1@fred.mathworks.com>...
> > %I have a 100x100 matrix:
> >
> > clear
> >
> > A = zeros(100, 100);
> >
> > A(45:54,45:54) = 1;
> >
> > %I want to create a new matrix as follows:
> >
> > yt = unifrnd(0,1,1);
> >
> > if yt < 0.25;
> > A1 = zeros(100,100);
> > A1(:,51:100) = A(:,51:100);
> > A(:,51:100) = 0;
> > else
> > A;
> > end
> >
> > %This will be part of a much longer loop, but what I really need is to know
> > %how to automate the naming of the new matrix that is created - so that for
> > %this case A1 it is named with the letter of it's parent matrix (A), and then the
> > %number 1 because it is the first daughter matrix, but that if in the next
> > %round, yt < 0.25 the next new matrix that is created will be called A2,
> > %and so on. (As well, at if A1 were to create a daughter matrix as well,
> > %then I would like it to be named A11, A12 and so on..)
> >
> > %The idea behind this is to track the lineage of the matrices
>
> Don't do this!
>
> Unfortunately the FAQ is down so we can't link you directly to it. I believe it was question 4.12.

What do you mean "don't do this"?
I am simulation species over time, and have to create new matrices to represent species which have evolved.

Subject: Automating naming of new matrices

From: someone

Date: 8 Nov, 2010 19:11:04

Message: 4 of 5

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ib9fk1$eme$1@fred.mathworks.com>...
> "SG " <sigrdson@gmail.com> wrote in message <ib9esr$r2c$1@fred.mathworks.com>...
> > %I have a 100x100 matrix:
> >
> > clear
> >
> > A = zeros(100, 100);
> >
> > A(45:54,45:54) = 1;
> >
> > %I want to create a new matrix as follows:
> >
> > yt = unifrnd(0,1,1);
> >
> > if yt < 0.25;
> > A1 = zeros(100,100);
> > A1(:,51:100) = A(:,51:100);
> > A(:,51:100) = 0;
> > else
> > A;
> > end
> >
> > %This will be part of a much longer loop, but what I really need is to know
> > %how to automate the naming of the new matrix that is created - so that for
> > %this case A1 it is named with the letter of it's parent matrix (A), and then the
> > %number 1 because it is the first daughter matrix, but that if in the next
> > %round, yt < 0.25 the next new matrix that is created will be called A2,
> > %and so on. (As well, at if A1 were to create a daughter matrix as well,
> > %then I would like it to be named A11, A12 and so on..)
> >
> > %The idea behind this is to track the lineage of the matrices
>
> Don't do this!
>
> Unfortunately the FAQ is down so we can't link you directly to it. I believe it was question 4.12.

For now, look at the answer to Q3.6 of this link:

http://www.mit.edu/~pwb/cssm/matlab-faq_toc.html

Subject: Automating naming of new matrices

From: someone

Date: 8 Nov, 2010 19:16:03

Message: 5 of 5

"SG " <sigrdson@gmail.com> wrote in message <ib9hoo$6hg$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ib9fk1$eme$1@fred.mathworks.com>...
> > "SG " <sigrdson@gmail.com> wrote in message <ib9esr$r2c$1@fred.mathworks.com>...
> > > %I have a 100x100 matrix:
> > >
> > > clear
> > >
> > > A = zeros(100, 100);
> > >
> > > A(45:54,45:54) = 1;
> > >
> > > %I want to create a new matrix as follows:
> > >
> > > yt = unifrnd(0,1,1);
> > >
> > > if yt < 0.25;
> > > A1 = zeros(100,100);
> > > A1(:,51:100) = A(:,51:100);
> > > A(:,51:100) = 0;
> > > else
> > > A;
> > > end
> > >
> > > %This will be part of a much longer loop, but what I really need is to know
> > > %how to automate the naming of the new matrix that is created - so that for
> > > %this case A1 it is named with the letter of it's parent matrix (A), and then the
> > > %number 1 because it is the first daughter matrix, but that if in the next
> > > %round, yt < 0.25 the next new matrix that is created will be called A2,
> > > %and so on. (As well, at if A1 were to create a daughter matrix as well,
> > > %then I would like it to be named A11, A12 and so on..)
> > >
> > > %The idea behind this is to track the lineage of the matrices
> >
> > Don't do this!
> >
> > Unfortunately the FAQ is down so we can't link you directly to it. I believe it was question 4.12.
>
> What do you mean "don't do this"?
> I am simulation species over time, and have to create new matrices to represent species which have evolved.

Use cell arrays instead.

Look at the answer to Q3.6 at this link (for now):

http://www.mit.edu/~pwb/cssm/matlab-faq_toc.html

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