How increase the value of each cell from 256*256 to 576*720

1 回表示 (過去 30 日間)
Bajdar Nour
Bajdar Nour 2018 年 9 月 4 日
編集済み: Guillaume 2018 年 9 月 10 日
function [DifferenceStatistic] = jfDStatsN(M)
dVEC(size(M, 1))= 0;
lvl = (size(M, 1)^2);
for i = 1:size(M, 1)
for j = 1:size(M, 2)
dVEC(abs(i - j) + 1) = dVEC(abs(i - j) + 1) + double(M(i,j));
end
end
end
. . .
it gives me this error
Attempted to access dVEC(577); index out of bounds because numel(dVEC)=576.
Error in jfDStatsN (line 12)
dVEC(abs(i - j) + 1) = dVEC(abs(i - j) + 1) + double(M(i,j));
  5 件のコメント
Bajdar Nour
Bajdar Nour 2018 年 9 月 10 日
Dear @Geoff dVEC is 576x720 matrix,,I want to extract some features on 576x720 images..but this code is worked only when M is square dimensions(512X512 or 456X456 just for example), otherwise is not working
Guillaume
Guillaume 2018 年 9 月 10 日
編集済み: Guillaume 2018 年 9 月 10 日
Maybe the code in the question has been modified, but as it is now, the code initialises dVEC as a 1 x W vector, with W the height of the input matrix M. If the width of the M matrix is greater than twice its height then the code will indeed error.
It's difficult to know what is valid in the code in the question since the none of variables created in the function match the function output variable.

サインインしてコメントする。

回答 (1 件)

Guillaume
Guillaume 2018 年 9 月 10 日
If the intent is to calculate the sum of the diagonals of the matrix (corresponding upper and lower diagonals being sum together), then this can be achieved simply with:
indices = toeplitz(1:size(M, 1), 1:size(M, 2));
dVEC = accumarray(indices(:), M(:));

カテゴリ

Help Center および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by