Multidimensional array multiplication issue

I have to matrices. Impulse = 32 by 32 , residual = 5021 by 32. I want each element in the columns in impulse to be multiplied with all elements of residual. This will be repeated for second column and added to the first. I want this for all the columns, with a loop. Please suggest...

2 comentarios

KL
KL el 22 de Oct. de 2017
what do you mean by "each element in the columns in impulse to be multiplied with all elements of residual"?
residual has 5021 rows and 32 columns. Do you want to create a product of all these elements?
Raisul Islam
Raisul Islam el 22 de Oct. de 2017
Thank you for your response KL. Impulse matrix must be multiplied in response matrix. So first each row of impulse matrix will be multiplied with the entire residual matrix. Then the second row of the impulse matrix will be multiplied with entire residual matrix. These two steps will be added. And then the third row will be multiplied with residual and added to first two stages. The output will have 5021 rows and 32 columns. I am checking the impact of impulse matrix on the entire residual matrix. This must be done with nested loops. I need to plot the 5021 rows for 32 variables. I will really appreciate your suggestion.

Iniciar sesión para comentar.

Respuestas (1)

KL
KL el 22 de Oct. de 2017
It's a simple matrix multiplication, isn't it?
impulse_matrix = rand(32,32);
residue_matrix = rand(5021,32);
mult_result = residue_matrix*impulse_matrix;

12 comentarios

Raisul Islam
Raisul Islam el 22 de Oct. de 2017
Editada: Raisul Islam el 22 de Oct. de 2017
Well, I could not explain it better my friend. Suppose we have just two variables. In that case, impulse_matrix = rand(2,2); Residue_ matrix= rand(5021,2); Now, all elements of impulse_matrix will be multiplied to first element of residu_matrix. Then the loop will move to the second element down the row of residu. Then the loop will be move down until the last element. Now this is for residue_matrix (:,1) . The loop will move across the columns . The same process will happen for residue_matrix (:,2). Now the two columns will be added to produce one column of size 5021 by 32. I need a for loop that can do this for no matter how many variables I add. I guess you might get a 3 dimensional matrix as an output. But as long as the 5021 rows in column 1 I am fine. The output called shock might be 5021 by 32 by 32. I also need to generalise the output.
Andrei Bobrov
Andrei Bobrov el 22 de Oct. de 2017
Let impulse_matrix = [1 2;3 4]; residue_matrix = [1 2; 2 1; 1 3];. Please set result.
KL
KL el 22 de Oct. de 2017
Editada: KL el 22 de Oct. de 2017
I feel like you'd want something like,
result = cumsum(residue_matrix,2)*prod(prod(impulse_matrix))
in this case, if you consider the matrices Andrei gave you, the result would be,
result =
24 72
48 72
24 96
Raisul Islam
Raisul Islam el 22 de Oct. de 2017
KL and Andrei, Thank you so much. This executes. Not what I was expecting. My signal looks like white noise. Anyway, I am really grateful for your amazing help. Thank you again.
Raisul Islam
Raisul Islam el 22 de Oct. de 2017
Editada: Raisul Islam el 22 de Oct. de 2017
Help me again. I tried this HD.shock = zeros(nobs+nlag,nvar,nvar); % [nobs x shock x var] for i=1:nvar for j=1:nvar HD.shock(:,j,i) = [nan(nlag,1); HDshock(i,2:end,j)']; end end Now I have a 3d Matrix of size (with 32 variables) ,31 by 5141 by 31. I want to plot this. if this is Y, what will i set as X? I want a 2d plot.
Can I make this 3d matrix a 2d one bu doing HDdim=shock(:,:,1)+shock(:,:,2)+shock(:,:,3)+shock(:,:,4)+shock(:,:,5)+shock(:,:,6)+shock(:,:,7)+shock(:,:,8)... +shock(:,:,9)+shock(:,:,10)+shock(:,:,11)+shock(:,:,12)+shock(:,:,13)+shock(:,:,14)+shock(:,:,15)+... shock(:,:,16)+shock(:,:,17)+shock(:,:,18)+shock(:,:,19)+shock(:,:,20)+shock(:,:,21)+shock(:,:,22)+... shock(:,:,23)+shock(:,:,24)+shock(:,:,25)+shock(:,:,26)+shock(:,:,27)+shock(:,:,28)+shock(:,:,29)+... shock(:,:,30)+shock(:,:,31)+shock(:,:,32) I find HDdim is a 2d. Can I do this in a loop?
With the first piece of code, I cannot clearly understand what you're doing but I would say you possibly could create your 3D matrix without using those 2 loops.
Then if you only have the Y data and you want to visualize, your can simply say
plot(your_y_data)
To make a sum along the third dimension, you just need
HDdim = sum(shock,3);
Raisul Islam
Raisul Islam el 23 de Oct. de 2017
Thanks KL, you are awesome dude. I have this HD(5000,32,32) . I want to extract just the first dimension and plot it. I don’t need the other two dimensions. Can you suggest how I can do that?
What do you mean you don't need other two dimensions?
plot(HD(:,:,1)) %all rows and columns from page 1
plot(HD(1,:,1)) %first row, all columns from page 1
plot(HD(:,1,1)) %all rows, first column from page 1
If you want to concatenate certain row/column across all pages, do it like,
row_1_allpages = reshape(HD(1,:,:),1,size(HD,2)*size(HD,3))
Raisul Islam
Raisul Islam el 23 de Oct. de 2017
Thank you so much.Great help.
Raisul Islam
Raisul Islam el 23 de Oct. de 2017
How can i concatenate column_1_allpages?
KL
KL el 24 de Oct. de 2017
Editada: KL el 24 de Oct. de 2017
col_1_allpages = reshape(HD(:,1,:),[],1)
Raisul Islam
Raisul Islam el 24 de Oct. de 2017
Editada: Raisul Islam el 25 de Oct. de 2017
KL mate, with result = cumsum(residue_matrix,2)*prod(prod(impulse_matrix))
for some reason I get 0 kin all elements of output matrix. I tried this way,
impulse=impulse(:); residual=v; [m,n]=size(v); HD=[];
for i=1:m
for j=1:n
HD = impulse(:).*v(i);
end
end
GHD=zscore(HD);
The problem is with the for loop I get the output for the first column only. So I get HD= p by 1 matrix. I want HD =p by 32 matrix. Currently, my impulses elements are multiplied with elements with the rows for the first column only. What modification should I do here to have all elements of impulse to be multiplied with all other columns just as it does for the first column in this loop. So I just need the same operation executed across all columns of v. What might be the nested loop? I appreciate your skilled solutions. As you see I am a new user, you are helping a lot.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Oct. de 2017

Editada:

el 25 de Oct. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by