私はまったくドキュメントの単純な例のために、matlabの思考のベクトル化の方法を得ていません。私は誰かが私の理解を少し助けてくれることを願っています。ベクトル化コード
私が達成しようとしているのは、ncols x nrows x ielementsの行列からNxNのサンプルを取り出し、各要素の平均を計算し、平均値の最大値を格納することです。 forループを使用すると、コードは次のようになります。
for x = 1+margin : nrows-margin
for y = 1+margin : ncols-margin
for i=1:ielem
% take a NxN sample
sample = input_matrix(y-margin:y+margin,x-margin:x+margin,i)
% compute the average of all elements
result(i) = mean2(sample);
end %for i
% store the max of the computed averages
output_matrix(y,x)=max(result);
end %for y
end %for x
誰でもこの状況の良い例をベクトル化できますか? T
'conv2'または' filter2'関数を見てください。 –
私はそうするでしょうが、conv2やfilter2のような関数を使ってこのタイプのコードをベクトル化し、より多くの行列インデックスを使用する方法はありますか? – VisLab