Removing a TEX arrow symbol from String

15 visualizaciones (últimos 30 días)
Jason
Jason el 13 de Feb. de 2020
Comentada: Jason el 13 de Feb. de 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?

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Labels and Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by