Multiply matrices of different sizes
Show older comments
Background: I've got 7 years worth of Power data for a wind farm binned into 100 bins of wind speed i.e. 100 x 7 matrix. I've got probability of each of that bin happening i.e. 100 x 1 matrix. I would like to multiply the elements of 100x7 matrix by elements in a 100x1 matrix to get cumulative probability of power output.
In simple term: how do I multiply 100x7 matrix by 100x 1 matrix? Tried bsxfun but didn't work.
2 Comments
Jan
on 16 Mar 2018
"Didn't work" is a weak explanation. Better post your code and the complete error message. Not that bsxfun will be the solution, so letting us guess, what fails in your case, is not useful.
Accepted Answer
More Answers (1)
Geoff Hayes
on 14 Mar 2018
NMans - if you want to multiply each column of the 100x7 matrix by the 100x1 matrix, then you could use bsxfun as
X = randi(255,100,7); % generate some dummy data
Y = rand(100,1);
Z = bsxfun(@times,X,Y);
Or are you trying to do something else?
3 Comments
NMans
on 15 Mar 2018
Geoff Hayes
on 16 Mar 2018
NMans - when I run the code that I posted in my answer, Z is a 100x7 matrix. Are you sure that your answer is 100x100?
NMans
on 19 Mar 2018
Edited: Walter Roberson
on 19 Mar 2018
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!