## Question about strings on a matrix.

Asked by Portgas Ace

### Portgas Ace (view profile)

on 2 Oct 2012
Accepted Answer by Matt Fig

### Matt Fig (view profile)

my matrix looks like this.
' A ' 'B' 'C'
'D' 'E' 'F'
'G' 'H' 'I'
how do i remove the ' '?

### Matt Fig (view profile)

Answer by Matt Fig

### Matt Fig (view profile)

on 2 Oct 2012
Edited by Matt Fig

### Matt Fig (view profile)

on 2 Oct 2012

It looks like you have a cell array of strings. The single quotes only appear when the array displays; they are not part of the strings. Note how the display changes depending on how the cell is viewed:
C = {'A', 'Bee', 'Ce'} % We see the single quotes - cell array
C{:} % We don't.
If you want to change to a character array, the quotes will not display:
D = char(C)
But now things are not so easy to deal with... For example, look at:
size(D)

### Image Analyst (view profile)

Answer by Image Analyst

### Image Analyst (view profile)

on 2 Oct 2012

Like Matt says, they're not really there. You see them just as an artifact of how you displayed them. Use fprintf() if you want to display them in some custom way, like without quotes.
clc;
ca = {'A' 'B' 'C';...
'D' 'E' 'F';...
'G' 'H' 'I'}
for row = 1 : 3
fprintf('%c %c %c\n', ca{row,1}, ca{row,2}, ca{row,3});
end
In the command window:
ca =
'A' 'B' 'C'
'D' 'E' 'F'
'G' 'H' 'I'
A B C
D E F
G H I

on 2 Oct 2012
Edited by Jan

### Jan (view profile)

on 2 Oct 2012

As far as I understand, James does not want to remove a quote, but the spaces surrounding 'A'.
C = {' A ', 'B', 'C'; ...
'D', 'E', 'F';...
'G', 'H', 'I'};
D = strrep(C, ' ', '');
strtrim is another alternative.

### Azzi Abdelmalek (view profile)

Answer by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 2 Oct 2012
Edited by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 2 Oct 2012

A={' A ' 'B' 'C'
'D' 'E' 'F'
'G' 'H' 'I'}
B=strtrim(A)
out=sprintf('%c %c %c \n',char(B'));
disp(out)