フィルターのクリア

Is there a way to "vectorize" this segment of code?

1 回表示 (過去 30 日間)
David Rikert
David Rikert 2024 年 2 月 10 日
コメント済み: David Rikert 2024 年 2 月 10 日
% 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 件のコメント
Matt J
Matt J 2024 年 2 月 10 日
We don't have the input permsList, so we do not know what anything is.

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2024 年 2 月 10 日
移動済み: Matt J 2024 年 2 月 10 日
S = string(randi([0,9], 5,4))
S = 5×4 string array
"0" "4" "8" "8" "6" "1" "1" "3" "8" "2" "6" "7" "2" "8" "5" "5" "7" "2" "6" "6"
D = str2double(join(S,""))
D = 5×1
488 6113 8267 2855 7266
  1 件のコメント
David Rikert
David Rikert 2024 年 2 月 10 日
Very clean. Thank you.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
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))
permsList = 5×4 string array
"5" "0" "3" "3" "1" "6" "6" "9" "4" "9" "5" "9" "5" "3" "2" "3" "8" "7" "7" "0"
permsNbrs = str2double(permsList)*10.^( width(permsList)-1:-1:0)'
permsNbrs = 5×1
5033 1669 4959 5323 8770
  2 件のコメント
David Rikert
David Rikert 2024 年 2 月 10 日
Thanks. Exactly what I was looking for.
Matt J
Matt J 2024 年 2 月 10 日
You're quite welcome, but please Accept-click the answer (green button) to indicate so.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by