Removing a TEX arrow symbol from String

16 Ansichten (letzte 30 Tage)
Jason
Jason am 13 Feb. 2020
Kommentiert: Jason am 13 Feb. 2020
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?

Akzeptierte Antwort

Subhadeep Koley
Subhadeep Koley am 13 Feb. 2020
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 Kommentar
Jason
Jason am 13 Feb. 2020
Thanks. I had assumed erase would not do anything if the S1 or S2 weren't present.
Jason

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by