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!