How can I creat a empty string?

69 ビュー (過去 30 日間)
Yang
Yang 2019 年 5 月 14 日
コメント済み: Walter Roberson 2019 年 6 月 1 日
Hi,
I need to add string to a string array, but I cannot get the results with length of 3 (like the matrix in the following code), but 4 with a empty string("") for first element. How can I create a empty string? or any alternertive approach for this purpose? Thank you very much
Example:
% for matrix
a = [];
for i = 1:3
a(end+1) = 1;
end
results: a = 1 1 1
% for string
a = string(); % a = strings; a = ""; works same
for i = 1:3
a(end+1) = "1";
end
results: a =
1×4 string array
"" "1" "1" "1"

採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 5 月 14 日
% for string
a = string([]);
for i = 1:3
a(end+1) = "1";
end

その他の回答 (1 件)

Shiv  Kumar
Shiv Kumar 2019 年 5 月 14 日
std::string a;
if(a.empty())
{
}
or
std::string a;
if(!a.empty())
{
}
a = "42";
if(!a.empty())
{
}
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 6 月 1 日
This is not MATLAB code, it is C++ code. It is not clear what the relevance of it is?

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by