Inserting variables into strings?
325 ビュー (過去 30 日間)
古いコメントを表示
In Charp I regulaly use
string newstring = $"This string is really easy to change as needed - since just put any data type here - {datatype} the complier takes care of it and consolidates to a single string.";
Am I missing something, is there a way to do this in matlab?
2 件のコメント
Voss
2024 年 6 月 7 日
Another option:
x = 24;
y = 24.5;
str1 = "The highest number is " + x + ", and that's it!";
str2 = "What about " + y + "?";
str1,str2
回答 (1 件)
Taylor
2024 年 7 月 2 日
The modern "string" datatype is much more intuitve in my opinion, so I recommend Voss' approach over using "fprintf" or "sprintf". It also allows for vectorized usage as well:
x = 1:5;
str = "myFile";
str + x
It is also much more capable when it comes to text analytics as well. This was actually the motivation behind creating the new "string" class instead of just using "char".
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!