# Matlab: how to use an array in a matrix

1. May 20, 2010

### elham.n

hi all..

I have a 2x2 matrix and an array , for example:

a=linspace(0,12) %this is my frequency range.

B=[2*a 3*a-1
a./2 a]

this one does not results a 2x2 matrix, that I need it to have ...B2xB1xB
how could i get a 2x2 matrix? should i use a loop instead of an array?
tnx alot.

Elham

2. May 20, 2010

### D H

Staff Emeritus
What are you trying to accomplish here, elham?

3. May 20, 2010

### D H

Staff Emeritus
With what?

What you have here a 2x2x100 array -- which is exactly what you asked for. You just don't know that that is what you asked for.

What you want is something different, apparently a plain old vanilla 2x2 matrix. I don't know how to read your mind, let alone a dumb program like Matlab. It only does what you tell it to do. Matlab, like all other languages built to date, does not have a DWIM (do what I mean) command.

4. May 20, 2010

### D H

Staff Emeritus
Matlab did exactly what you told it to do. That apparently is not what you want it to do.

So what exactly are you trying to accomplish?

5. May 21, 2010

### elham.n

I know what u mean!!and I do not expect MATLAB to do s.th strange..
I want to replace this array's elements in this matrix.
i will use a matrix like this as the transfer matrix in PC structures,and multiplicantion of these matrices for every layer,but with this selected array , i face some problems. and multiplicantion of these matrices is impossible.
so i need square matrix..and I was only confused
tnx alot..I solved this problem with a FOR loop.
thank u.