Matlab and preparing matrix lines

  • MATLAB
  • Thread starter hokhani
  • Start date
  • #1
443
7

Main Question or Discussion Point

In the Matlab program below

U=[210; 100; 150]
ky= linspace(-.2,.2);
qx=sqrt(((150-U)/.2)^2-ky.^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).
 

Answers and Replies

  • #2
RUber
Homework Helper
1,687
344
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.
 

Related Threads on Matlab and preparing matrix lines

Replies
5
Views
43K
  • Last Post
Replies
13
Views
2K
Replies
0
Views
8K
Replies
1
Views
2K
Replies
1
Views
595
Replies
0
Views
3K
Replies
0
Views
4K
Replies
1
Views
5K
Replies
1
Views
17K
Replies
2
Views
10K
Top