How can I multiply a vector (n*1) by each row of a matrix (m*v) to generate m (n*v) matrices?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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?!
採用された回答
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 件のコメント
B = (100*1)
Each row is (1*72),
Thus BK is (100*1)*(1*72) so it should... sorry i should have clarified, i want B multiplied by each row of the big matrix...
The above is just an example for you to see if it is doing what you want by looking at the results and initial inputs. From what you are describing,
K = round(rand(1000,72)*10);
z = round(rand(100,1)*10);
T = cell(size(K,1),1);
for ii = 1:size(K,1)
T{ii} = z*K(ii,:);
end
length(T) % should be 1000 cells
size(T{1}) % each matrix in each cell should be 100-by-72
Yes, this is along the lines of what I need. Basically, the output I need to proceed is the 1000 matrices which are 110-by-72.
I need these as new variables, ideally named something like BK0001-BK1000,
OK, can someone then please explain the easiest way for me to get these 1000 matrices, and in some form so that I can perform further matrix manipulations on them? Apologies for my being a NOOB. :)
Sure, always willing to help a noob! Since all of the matrices are the same size stack them along the third dimension. That way you can refer to them by slice.
M = rand(110,72,1000); %random 3d matrix
Now you can reference the 462nd matrix with
M(:,:,462)
etc. How you get it into this form will depend on how its structured right now.
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
Thanks guys, your help is much appreciated. I'll have a bash with this and see how i get on!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
