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

Matlab and preparing matrix lines

  1. Jan 30, 2015 #1
    In the Matlab program below

    U=[210; 100; 150]
    ky= linspace(-.2,.2);

    I want to have qx as a matrix in which each row is corresponding to one value of U: the first row corresponds to 210, the second to 100 and .... How should I do this? (I want to avoid the "for loop" if possible).
  2. jcsd
  3. Jan 30, 2015 #2


    User Avatar
    Homework Helper

    One way would be to make intermediate matrices so that the dimensions agree.
    U2 = U * ones(1,100);
    Y2 = ones(3,1)*ky;
    Then your function will be referring to the same index in both reference matrix.
    There might be a better way that is more effecient with your storage space, but for reasonably sized problems, this would do the trick.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook