0

Trying to print the following range of labels in a figure:

aux = {'ca155.mat','ca154.mat','ca159.mat','ca146.mat','ca148.mat','ca004.mat'};

But I need it upper case and without the extension, so I use

text(0,0,upper(sprintf([aux{i},'\b\b\b\b'])));

In the command window I get the correct output such as for i=1, i.e. CA155. However the text function on a figure doesn't work and produces:

CA155.MAT[][][][]

Except instead of brackets there are closed rectangles (I couldn't copy the character).

How can I fix this?

1
  • 1
    Instead of producing a character that deletes the previous character in a command window, why not just delete the characters from the array? aux{1}(1:end-4) removes the last 4 characters from a string. Commented Jan 14, 2020 at 20:02

1 Answer 1

1

When processing your text, you did not delete the extension, you inserted backspaces. Here some insights for demonstration:

>> x=upper(sprintf([aux{i},'\b\b\b\b']))

x =

    'CA155'

>> size(x)

ans =

     1    13

>> x(1:9)

ans =

    'CA155.MAT'

>> x(1:10)

ans =

    'CA155.MA'

The first 9 characters are still there but the following backspaces delete them when working in a command window. Looks like text does not support it, and backspaces are definitely not the way to go.

Use fileparts instead:

>> [filepath,name,ext]=fileparts(aux{i})

filepath =

  0×0 empty char array


name =

    'ca155'


ext =

    '.mat'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.