MATLAB 2022b removing spaces from strings in concatenation?

11 ビュー (過去 30 日間)
Tahsin Emir Ersoy
Tahsin Emir Ersoy 2022 年 11 月 29 日
コメント済み: Tahsin Emir Ersoy 2022 年 11 月 29 日
I just tried to plot this but the space after Nozzle Number is being removed?
for i=1:19
plot(pressures_spray_angle,spray_angle(i,:),'-*','LineWidth',2,'DisplayName',strcat('Nozzle Number ',num2str(nozzle_numbers(i))));
end
Also I tried to concatenate with a + and that did not work.
Is this a MATLAB 2022b thing? If so, please name out the software engineer who implemented it and approved it for accountability purposes :D
  2 件のコメント
Stephen23
Stephen23 2022 年 11 月 29 日
"Is this a MATLAB 2022b thing?"
No, STRCAT has always trimmed trailing whitespace from character arrays, as the last example from this 2012 archive of the documentation shows:
Every archived version of the documentation shows/explains this.
Tahsin Emir Ersoy
Tahsin Emir Ersoy 2022 年 11 月 29 日
you are right on this one, my bad.

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

採用された回答

Jonas
Jonas 2022 年 11 月 29 日
編集済み: Jonas 2022 年 11 月 29 日
"For character array inputs, strcat removes trailing ASCII whitespace characters: space, tab, vertical tab, newline, carriage return, and form feed. For cell array and string array inputs, strcat does not remove trailing white space."
use [] or horzcat please
tx1='hello ';
tx2='world ';
number=rand();
[tx1 tx2 num2str(number)]
ans = 'hello world 0.021847'
horzcat(tx1,tx2,num2str(number))
ans = 'hello world 0.021847'
strcat(tx1,tx2,num2str(number))
ans = 'helloworld0.021847'
using + is only suported for strings not character arrays:
"hello " + "world"
ans = "hello world"
class("hello " + "world")
ans = 'string'
class(tx1)
ans = 'char'
  3 件のコメント
Jonas
Jonas 2022 年 11 月 29 日
happy to help. if you do not have any more question, please accept the answer
Tahsin Emir Ersoy
Tahsin Emir Ersoy 2022 年 11 月 29 日
Just accepted, thanks again.

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by