Nested loop related issue
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Image Analyst
2017 年 10 月 25 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!