Filter löschen
Filter löschen

Question about strings on a matrix.

1 Ansicht (letzte 30 Tage)
Portgas Ace
Portgas Ace am 2 Okt. 2012
my matrix looks like this.
' A ' 'B' 'C'
'D' 'E' 'F'
'G' 'H' 'I'
how do i remove the ' '?

Akzeptierte Antwort

Matt Fig
Matt Fig am 2 Okt. 2012
Bearbeitet: Matt Fig am 2 Okt. 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)

Weitere Antworten (3)

Image Analyst
Image Analyst am 2 Okt. 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 am 2 Okt. 2012
Bearbeitet: Jan am 2 Okt. 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 am 2 Okt. 2012
Bearbeitet: Azzi Abdelmalek am 2 Okt. 2012
A={' A ' 'B' 'C'
'D' 'E' 'F'
'G' 'H' 'I'}
B=strtrim(A)
out=sprintf('%c %c %c \n',char(B'));
disp(out)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by