フィルターのクリア

Removing a TEX arrow symbol from String

8 ビュー (過去 30 日間)
Jason
Jason 2020 年 2 月 13 日
コメント済み: Jason 2020 年 2 月 13 日
hello.
I have several text objects on a plot that I want to alter. Its actually created using the TEX interpreter in the text function:
txt='E4E'
txt=horzcat('\leftarrow',txt);
text(app.UIAxes,x,y,txt,'Color',cl,'FontSize',12,'Interpreter', 'tex','HorizontalAlignment','left','VerticalAlignment','middle');
Sometimes the rightarrow is used.
Text (532 E4E\rightarrow) with properties:
String: '532 E4\rightarrow'
FontSize: 20
FontWeight: 'normal'
FontName: 'Helvetica'
Color: [0 1 0]
HorizontalAlignment: 'left'
Position: [320 5100 0]
Units: 'data'
I want to remove the arrows, and have tried this.
htext=findobj(app.UIAxes,'Type','text');
n=numel(htext);
for i=1:n
h=htext(i)
s1='\rightarrow'
s2='\leftarrow'
newStr=erase(h.String,s1); %Delete S1 if present
newStr=erase(h.String,s1); %Delete S2 if present
h.String=newStr; %reassign
end
But it only does one arrow orientation?

採用された回答

Subhadeep Koley
Subhadeep Koley 2020 年 2 月 13 日
Your code is almost correct but, before erasing you need to check whether the h.String contains \leftarrow or \rightarrow. Use the code below.
htext=findobj(app.UIAxes, 'Type', 'text');
n = numel(htext);
for i = 1:n
h = htext(i);
s1 = '\rightarrow';
s2 = '\leftarrow';
if contains(h.String, s1,'IgnoreCase',true)
newStr = erase(h.String,s1);
h.String = newStr;
else
newStr = erase(h.String,s2);
h.String = newStr;
end
end
  1 件のコメント
Jason
Jason 2020 年 2 月 13 日
Thanks. I had assumed erase would not do anything if the S1 or S2 weren't present.
Jason

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by