Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: Call a matrix in program

$
0
0
"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

Viewing all articles
Browse latest Browse all 19628

Trending Articles