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:
Call a matrix in program

Subject: Call a matrix in program

From: Babak

Date: 17 Jul, 2013 10:32:25

Message: 1 of 4

Hi. I want to call a matrix in my program. I have 9 different matrix (standard matrix) which is calculated before( it was time consuming!). Now I want to call them and compare the new calculated matrix with them( all matrix are the same size).
two question:
1- how can I call them for comparison. ( how can I have a access to them without repeating calculations)

2- the 9 standard saved matrix have different name. how can I call them in a simple loop for comparison?
EX:
for i=1:9
b =standard matrix(1_9)
b1=new matrix
similarity(b, new matrix) % Similarity is function and I wrote it before
end

Subject: Call a matrix in program

From: Nasser M. Abbasi

Date: 17 Jul, 2013 10:55:29

Message: 2 of 4

On 7/17/2013 5:32 AM, Babak wrote:
> Hi. I want to call a matrix in my program.

One does not "call" a matrix, since a matrix is not a function. It is a variable?

>I have 9 different matrix (standard matrix) which is calculated before( it was time consuming!).
>Now I want to call themand compare the new calculated matrix with them( all matrix are the same size).
> two question:
> 1- how can I call them for comparison. ( how can I have a access to them without repeating calculations)

use a norm?

>
> 2- the 9 standard saved matrix have different name. how can I call them in a simple loop for comparison?

Do not use a "name" for each. Since they are same size, use one name for all "A",
and use an index to reference each. A(:,:,i)

i.e. Put all your matrices in one 3D matrix, and use the page number as the index of
each 2D matrix. (make sure to pre-allocate the space before)

> EX:
> for i=1:9
> b =standard matrix(1_9)
> b1=new matrix
> similarity(b, new matrix) % Similarity is function and I wrote it before
> end
>

--Nasser

Subject: Call a matrix in program

From: Babak

Date: 17 Jul, 2013 11:54:08

Message: 3 of 4

"Nasser M. Abbasi" wrote in message <ks5t70$uit$2@speranza.aioe.org>...
> On 7/17/2013 5:32 AM, Babak wrote:
> > Hi. I want to call a matrix in my program.
>
> One does not "call" a matrix, since a matrix is not a function. It is a variable?
>
> >I have 9 different matrix (standard matrix) which is calculated before( it was time consuming!).
> >Now I want to call themand compare the new calculated matrix with them( all matrix are the same size).
> > two question:
> > 1- how can I call them for comparison. ( how can I have a access to them without repeating calculations)
>
> use a norm?
>
> >
> > 2- the 9 standard saved matrix have different name. how can I call them in a simple loop for comparison?
>
> Do not use a "name" for each. Since they are same size, use one name for all "A",
> and use an index to reference each. A(:,:,i)
>
> i.e. Put all your matrices in one 3D matrix, and use the page number as the index of
> each 2D matrix. (make sure to pre-allocate the space before)
>
> > EX:
> > for i=1:9
> > b =standard matrix(1_9)
> > b1=new matrix
> > similarity(b, new matrix) % Similarity is function and I wrote it before
> > end
> >
>
> --Nasser


Thanks Nasser for second part. It is solved :)
For first part for example I have:
standard1=[1 2; 3 4]
standard2=[2 5; 4 7]
standard3=[5 8; 9 3]
which are calculated before in another program.
Now I want to put each of above matrix in my function:
similarity(new-matrix, standard(i))

I don't want to calculate the all standard matrix again. When user put a new matrix I just want to call its results (standard(j)) and compare it with new matrix.

Subject: Call a matrix in program

From: Barry Williams

Date: 17 Jul, 2013 15:14:11

Message: 4 of 4

"Babak " <b_mn@hotmail.com> wrote in message <ks60l0$5fa$1@newscl01ah.mathworks.com>...
> "Nasser M. Abbasi" wrote in message <ks5t70$uit$2@speranza.aioe.org>...
> > On 7/17/2013 5:32 AM, Babak wrote:
> > > Hi. I want to call a matrix in my program.
> >
> > One does not "call" a matrix, since a matrix is not a function. It is a variable?
> >
> > >I have 9 different matrix (standard matrix) which is calculated before( it was time consuming!).
> > >Now I want to call themand compare the new calculated matrix with them( all matrix are the same size).
> > > two question:
> > > 1- how can I call them for comparison. ( how can I have a access to them without repeating calculations)
> >
> > use a norm?
> >
> > >
> > > 2- the 9 standard saved matrix have different name. how can I call them in a simple loop for comparison?
> >
> > Do not use a "name" for each. Since they are same size, use one name for all "A",
> > and use an index to reference each. A(:,:,i)
> >
> > i.e. Put all your matrices in one 3D matrix, and use the page number as the index of
> > each 2D matrix. (make sure to pre-allocate the space before)
> >
> > > EX:
> > > for i=1:9
> > > b =standard matrix(1_9)
> > > b1=new matrix
> > > similarity(b, new matrix) % Similarity is function and I wrote it before
> > > end
> > >
> >
> > --Nasser
>
>
> Thanks Nasser for second part. It is solved :)
> For first part for example I have:
> standard1=[1 2; 3 4]
> standard2=[2 5; 4 7]
> standard3=[5 8; 9 3]
> which are calculated before in another program.
> Now I want to put each of above matrix in my function:
> similarity(new-matrix, standard(i))
>
> I don't want to calculate the all standard matrix again. When user put a new matrix I just want to call its results (standard(j)) and compare it with new matrix.

You need to do what Nasser is suggesting. You can run your similarity check in a loop if you create a 3d matrix:

  standard(:,:,1) = [1 2; 3 4]; standard(:,:,2) = [2 5; 4 7];

and so forth.

You can then access each page of the 3d array by indexing to standard(:,:,n)

By the way, you're showing spaces in your variable names above.

Barry

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