How do I convert a string to a single quotes string?

55 ビュー (過去 30 日間)
Brando Miranda
Brando Miranda 2017 年 10 月 17 日
コメント済み: Guillaume 2018 年 9 月 26 日
I have a number N_train that I want to convert to a single quotes string (otherwise the title does not look as I want it):
title_name = ['Training data' string(N_train)]
though string returns a double quotes representation of the string for some reason. I tried making the first string double quotes but it doesn't fix it.
Is there a way to cast to single quotes strings in matlab?

回答 (2 件)

Guillaume
Guillaume 2017 年 10 月 17 日
single quote string is actually a char array. They were the only kind of strings available pre-R2016b. Anyway, to get a char array:
title_name = sprintf('Training Data %d', N_train);
or
title_name = compose('Training Data %d', N_train);
To get a string:
title_name = compose("Training Data %d", N_train);
  3 件のコメント
Leo OfNature
Leo OfNature 2018 年 9 月 26 日
Yes, you can use the function char() to convert your string
Guillaume
Guillaume 2018 年 9 月 26 日
char will not convert a number to its char array representation (which is what is asked here).

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


Sean de Wolski
Sean de Wolski 2017 年 10 月 17 日
titleName = "Training data " + N_train
?

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by