Matrix manipulation and matrix dimensions
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello Matlab community again,
I am still trying to figure out few steps with getting from one dimension to another in matlab matrices.
So here is what I have now, Two matrices; A(73400 by 30), the number of rows here(73400) is equal to 14680 of stacked (5*1) matrices/arrays, hence 14680*5=73400.
The second matrix B(14680,5)
My objective is to compute the sum of the product of the transpose of each (5*1) that is stacked in A & each row from B . So the sum of the product should yield one element in each column (1 through 30).
The final matrix C is then (14680 by 30)
I tired to use two loops:
for i=1:30;
for j=1:14680
C(i,j)= sum(A(j:n,i)'*B(j,:));
end
end
It did not work. But in words, every iteration from 1 through 30, pick up a (5*1) from A, transpose it so it is same dimensions as rows from B, then compute sum of the product of each row from (1:14680).
Matrix B is a constant input, so it doesn't change. The only change is the values from each column in A ( from 1 through 30).
I hope I explained this correctly this time.
Thank you so much guys!
Amine
0 Kommentare
Antworten (2)
David Goodmanson
am 13 Dez. 2016
Bearbeitet: David Goodmanson
am 13 Dez. 2016
Hello Amine, This is only an answer if the following idea is correct: For a given 5x1 (call it y) and if B is mx5, I think you are looking for the number
sum{k = 1 to m} sum((y.').*B(k,:)) which is the same as sum(B*y).
If not, you can ignore what's next. Anyway, the following seems to work in this case:
% A = m*5 x q
% B = m x 5
D = reshape(A,5,m*q) % line up 5x1's side by side
E = B*D % all possible dot products of a
% transposed 5x1 from A and a row of B
F = sum(E) % sum down rows of B
C = reshape(F,m,q) % place the elements
or in cryptic form
C = reshape(sum(B*reshape(A,5,m*q)),m,q)
2 Kommentare
David Goodmanson
am 13 Dez. 2016
Hello Amine, yes m = 14680, q = 30. If matrix A is 2d of size 73400 x 30, the reshape command for D pretty much has to work. I see from your comment to Jan's answer that you have extracted A from a 4d matrix. Could you check the size of A just before you try the reshape command? Thanks.
Jan
am 13 Dez. 2016
A = rand(73400, 30);
B = rand(14680, 5);
AA = reshape(A, 5, 14680 * 30);
C = reshape(B * AA, 14680, 14680, 30);
Result = sum(CC, 3);
Do you mean something like this? If not, please explain the wanted result again. What is the desired size? A small example might be useful also.
4 Kommentare
Jan
am 16 Dez. 2016
@Amine: Your descriptions are hard to read. I cannot follow you. Can you provide real values? Perhaps a 2x3 input instead of 73400x30 would clarify already, what you want to achieve. The error message shows, that you need a lot of RAM to claculate such large inputs efficiently. I do not know, if your machine has 120GB or only 4GB.
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!