Create an string array with strings having both char and numbers

1 回表示 (過去 30 日間)
Vinay Killamsetty
Vinay Killamsetty 2021 年 6 月 8 日
コメント済み: Vinay Killamsetty 2021 年 6 月 12 日
Could you help me in creating a string array with strings containing characters and numbers in a sorted manner
Eg:
I want to create a string array with strings {"Analysis_1", "Analysis_2", "Analysis_3", "Analysis_4", ......, "Analysis_n"}
The values of 'n' should be defined in way that it can be varied by the user.

採用された回答

David Hill
David Hill 2021 年 6 月 8 日
k=[];
for n=1:25;
k=[k,string(sprintf('Analysis_%d',n))];
end

その他の回答 (1 件)

Steven Lord
Steven Lord 2021 年 6 月 8 日
n = 5;
S = "Analysis_" + (1:n)
S = 1×5 string array
"Analysis_1" "Analysis_2" "Analysis_3" "Analysis_4" "Analysis_5"
You can also use implicit expansion to make an array if you so desired.
fruits = ["apple"; "banana"; "cherry"]
fruits = 3×1 string array
"apple" "banana" "cherry"
quantity = 1:4;
market = fruits + "_" + quantity
market = 3×4 string array
"apple_1" "apple_2" "apple_3" "apple_4" "banana_1" "banana_2" "banana_3" "banana_4" "cherry_1" "cherry_2" "cherry_3" "cherry_4"

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by