Extract subarray from array

9 ビュー (過去 30 日間)
longxia
longxia 2017 年 1 月 4 日
コメント済み: longxia 2017 年 1 月 4 日
I find a code which is used to extract subarray from array.but when I run it in MATLAB R2011,the command window shows:"Error using zeros,leading inputs must be numeric".I don't know the reason.the code are as following:
####################################################
function B = subarray(A, i1, i2, j1, j2, pad)
% B = subarray(A, i1, i2, j1, j2, pad)
% Extract subarray from array
% pad with boundary values if pad = 1
% pad with zeros if pad = 0
dim = size(A);
B = zeros(i2-i1+1, j2-j1+1, dim(3), 'like', A);
if pad
B((i1:i2)-i1+1, (j1:j2)-j1+1, :) = A(min(max(i1:i2, 1), dim(1)), min(max(j1:j2,1), dim(2)), :);
else
ai1 = max(i1, 1);
ai2 = min(i2, dim(1));
aj1 = max(j1, 1);
aj2 = min(j2, dim(2));
B((ai1:ai2)-i1+1, (aj1:aj2)-j1+1, :) = A(ai1:ai2, aj1:aj2, :);
end

採用された回答

Walter Roberson
Walter Roberson 2017 年 1 月 4 日
R2013a was the first release that supported the 'like' Keyword. Change your parameter from
'like', A
To
class(A)
Notice that is a single parameter that is not quoted
  1 件のコメント
longxia
longxia 2017 年 1 月 4 日
I made it,thank you very much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePhased Array Design and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by