Nested loop related issue
Ältere Kommentare anzeigen
Impulse = 961 by 1 double
residual = 5142 by 32 double
.
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? Should I use another for loop or a while loop inside..I appreciate your skilled solutions. As you see I am a new user, you are helping a lot.
3 Kommentare
KL
am 25 Okt. 2017
Hi Raisul,
here you're writing two loops but you're only using 'i' inside but not 'j', that's why it doesn't work as you expect it to be. I would recommend you to read about indexing on the following link: https://de.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html.
Coming to your question, firstly if impulse is already a column vector, writing
impulse = impulse(:);
doesn't really do anything. So you don't need it.
From your code, it looks like, this time you're trying to multiply impulse across all columns of v. But your v has 5142 rows while impulse has only 961 rows. How do you expect them to be multiplied then?
Raisul Islam
am 25 Okt. 2017
Raisul Islam
am 26 Okt. 2017
Antworten (1)
Image Analyst
am 25 Okt. 2017
SO many problems. First of all impulse was already converted to a column vector with your first line of code so you no longer need the(:) in
HD = impulse(:).*v(i);
Secondly, v is a 2-D array and takes two indexes. Since you only supplied 1 it's acting as a linear index and will go down rows first, but won't include the whole array, it will just have the first (badly-named) n elements (which is really columns) in the first column, which has m rows. Since m and n may not match up, you will either take less than the first column, or take more, in which case it will start to take some from the second column.
So this is better but I still can't figure out what you want to do.
% Turn impulse into a 961 by 1 column vector
impulse = impulse(:);
residual = v; % 5142 by 32
[rows, columns] = size(v);
HD = []; % ??????
for row = 1 : rows
for column = 1 : columns
HD = impulse(:) .* v(row, column);
end
end
GHD = zscore(HD);
Exactly what rows and columns of what do you want to multiply by the rows and columns of what else? I can't figure it out from your strange code. What dimensions do you expect HD to be when everything is all done? 961 is not an integer multiple of either 5142 or 32, so something is not going to align up right.
Third, you define residual but never use it - you continue to use v instead. Why?
4 Kommentare
Raisul Islam
am 25 Okt. 2017
Bearbeitet: Raisul Islam
am 25 Okt. 2017
Image Analyst
am 26 Okt. 2017
I honestly have no idea what you want to do. Do you have a mathematical formula (a picture) that shows what operation you are trying to do digitally?
Raisul Islam
am 26 Okt. 2017
Raisul Islam
am 26 Okt. 2017
Kategorien
Mehr zu Performance and Memory finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!