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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!