Removing a TEX arrow symbol from String

13 vues (au cours des 30 derniers jours)
Jason
Jason le 13 Fév 2020
Commenté : Jason le 13 Fév 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?

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Labels and Annotations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by