Using arrayfun on 2d matrix
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sameer Karim
le 7 Avr 2018
Réponse apportée : Walter Roberson
le 7 Avr 2018
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
0 commentaires
Réponse acceptée
Walter Roberson
le 7 Avr 2018
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur GPU Computing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!