Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab: how to use an array in a matrix

  1. May 20, 2010 #1
    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.

  2. jcsd
  3. May 20, 2010 #2

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    What are you trying to accomplish here, elham?
  4. May 20, 2010 #3

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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.
  5. May 20, 2010 #4

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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?
  6. May 21, 2010 #5
    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook