Question about strings on a matrix.

1 view (last 30 days)
my matrix looks like this.
' A ' 'B' 'C'
'D' 'E' 'F'
'G' 'H' 'I'
how do i remove the ' '?

Accepted Answer

Matt Fig
Matt Fig on 2 Oct 2012
Edited: Matt Fig 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)

More Answers (3)

Image Analyst
Image Analyst 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

Jan
Jan on 2 Oct 2012
Edited: Jan 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
Azzi Abdelmalek on 2 Oct 2012
Edited: Azzi Abdelmalek 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)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!