Info

この質問は閉じられています。 編集または回答するには再度開いてください。

fix a center of gravity loop

2 ビュー (過去 30 日間)
BA
BA 2022 年 7 月 27 日
閉鎖済み: Image Analyst 2022 年 7 月 28 日
imshow(matrix(:,:,1))
%identify axes
[x, y] = ginput(2);
% preallocate matrices
cog = zeros(size(matrix,3),1);
% the loop does not work and the error in the cog(i) line
% loop start
for i = 1:size(matrix,3)
I = matrix(:,:,i);
test = improfile(I,[x(1) x(2)],[y(1) y(2)]);
%the error comes from this line
cog(i) = sum((1:length(test)).*test)/sum(test);
% loop end
end
scog = (cog - min(cog)) / (max(cog) - min(cog));
  1 件のコメント
Matt J
Matt J 2022 年 7 月 27 日
You need to demonstrate the code and show us the error messages.

採用された回答

David Hill
David Hill 2022 年 7 月 27 日
cog(i) = sum((1:length(test)).*test')/sum(test); %need to transpose test' to match dimensions
  1 件のコメント
BA
BA 2022 年 7 月 27 日
編集済み: BA 2022 年 7 月 27 日
Fab. it works perfectly. I have another question: what is the equivalent of 'improfile' in octave? I mean to change the 'improfile' line to work in octave

その他の回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by