Azzera filtri
Azzera filtri

Question about strings on a matrix.

1 visualizzazione (ultimi 30 giorni)
Portgas Ace
Portgas Ace il 2 Ott 2012
my matrix looks like this.
' A ' 'B' 'C'
'D' 'E' 'F'
'G' 'H' 'I'
how do i remove the ' '?

Risposta accettata

Matt Fig
Matt Fig il 2 Ott 2012
Modificato: Matt Fig il 2 Ott 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)

Più risposte (3)

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

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by