Borrar filtros
Borrar filtros

Question about strings on a matrix.

1 visualización (últimos 30 días)
Portgas Ace
Portgas Ace el 2 de Oct. de 2012
my matrix looks like this.
' A ' 'B' 'C'
'D' 'E' 'F'
'G' 'H' 'I'
how do i remove the ' '?

Respuesta aceptada

Matt Fig
Matt Fig el 2 de Oct. de 2012
Editada: Matt Fig el 2 de Oct. de 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)

Más respuestas (3)

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

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by