Using arrayfun on 2d matrix

13 ビュー (過去 30 日間)
Sameer Karim
Sameer Karim 2018 年 4 月 7 日
回答済み: Walter Roberson 2018 年 4 月 7 日
for i = 1:D
Xtr = arrayfun(@(x) binarize(x, threshold), Xtrn(:, i));
end
Xtrn is a MxD matrix
Xtr is a MxD matrix
Can we vectorize this loop as well?
This is what binarize does
function X = binarize(X, threshold)
if(X<threshold)
X = 0;
else
X = 1;
end
end

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 7 日
You are overwriting all of Xtr in each iteration of i
You probably just want
Xtr = binarize(Xtrn, threshold)
with
function b = binarize(X, threshold)
b = X >= threshold;

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by