Is there a way to "vectorize" this segment of code?
1 次查看(过去 30 天)
显示 更早的评论
% 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 个评论
采纳的回答
更多回答(1 个)
Matt J
2024-2-10
编辑:Matt J
2024-2-10
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 个评论
Matt J
2024-2-10
You're quite welcome, but please Accept-click the answer (green button) to indicate so.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!