how to generate a matrix from another matrix
10 views (last 30 days)
Hi: I am having a matrix called "alpha" with size (1x50) and another matrix called "beta" which is related to alpha through the following relation: beta=0.001/alpha I wanted to get beta as another "1x50" matrix so the number "0.001" contributes to all the values in the matrix "alpha". can any one help me out with this? Naema
More Answers (2)
Andrew on 20 Jun 2014
Hello Naema. There is a really simple solution to this. All you have to do is use element operations by adding a dot.
A=randn(50); %generating a random 50x50 matrix
B=0.001./A; %note the dot before the slash.
The reason you need the dot is because when you use something/(a matrix) in matlab, it assumes that you are trying to solve a linear system. By adding in the dot you tell matlab that instead you want to perform the operation of 0.001/A for each element of A. This notation works for many operations as well.
For instance say you want to multiply all of the elements two matrices together. Then we could do:
Here the result C would be the element multiplication of matrices A and B. That is c_ij=a_ij*b_ij. Note that this is much different than usual matrix multiplication.
There are other operators this applies to as well, such as the exponential operator and the likes. It is very useful!