How can I multiply a vector (n*1) by each row of a matrix (m*v) to generate m (n*v) matrices?
1 回表示 (過去 30 日間)
古いコメントを表示
So in my simulation I have a matrix K (1000*72) = 1000 simulations of k And a vector B (100*1).
I need 1000 matrices of Bk
I've turned to MATLAB on the advice of an engineer...
Being completely new to MATLAB (and a coding rookie) I haven't much of a clue where to start...
Please can someone break this down nice and simply for me so I can crack on with the rest of my research?!
0 件のコメント
採用された回答
Matt Fig
2012 年 8 月 16 日
編集済み: Matt Fig
2012 年 8 月 16 日
If your matrix is 1000-by-72, you cannot multiply this by a 100-by-1. None of the dimensions match up. Each row of your matrix is 1-by-72, so how do you propose to multiply this by a 100-by-1?
The only way I can see that you mean would be something like this:
M = round(rand(5,3)*10)
z = round(rand(4,1)*10)
T = cell(size(M,1),1);
for ii = 1:size(M,1)
T{ii} = z*M(ii,:);
end
Now look at T{1}, T{2}, etc. I this what you mean?
8 件のコメント
Matt Fig
2012 年 8 月 16 日
編集済み: Matt Fig
2012 年 8 月 16 日
You have the 1000 matrices stored very efficiently in a cell array. If you need to use them further, simply use them like you would any other matrix. For example:
M = magic(3)
J = [2;3;4]
Result = M*J
But now look what happens if the matrix is stored in a cell array instead:
G = {magic(3)} % Store in cell array G.
Result2 = G{1}*J % You can loop, like G{ii}*J if G has many cells
isequal(Result,Result2) % Same-same
It might help if you read up on cell arrays in MATLAB. They are very useful for doing just what you need to do! I use them all the time for my job to hold large data sets, for example.
doc cell
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!