Is there a way to "vectorize" this segment of code?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
David Rikert
le 10 Fév 2024
Commenté : David Rikert
le 10 Fév 2024
% turn each of these string array rows into integers
[rows,cols] = size(permsList);
permsNbrs = zeros(rows,1);
a = string(permsList); % convert to string, so we can use strcat
for i = 1:rows
b = "";
for j = 1:cols
b = strcat(b,a(i,j));
end % for j
permsNbrs(i,1) = str2double(b);
end % for i
1 commentaire
Réponse acceptée
Plus de réponses (1)
Matt J
le 10 Fév 2024
Modifié(e) : Matt J
le 10 Fév 2024
I'm going to guess that this is what you are trying to do.
permsList=string(randi([0,9], 5,4))
permsNbrs = str2double(permsList)*10.^( width(permsList)-1:-1:0)'
2 commentaires
Matt J
le 10 Fév 2024
You're quite welcome, but please Accept-click the answer (green button) to indicate so.
Voir également
Catégories
En savoir plus sur Characters and Strings 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!