Borrar filtros
Borrar filtros

Removing 'quotes' from a cell array

51 visualizaciones (últimos 30 días)
susan
susan el 20 de Oct. de 2012
Movida: Rik el 6 de Mzo. de 2023
I have a cell array with 2 columns..
Column 1 is made up of 'a' ''b' 'c' '''d'
Column 2 is 123 456 678
I need to export this into a ASCII tab delimited file as a 123 b 456 c 678 ...
How can I remove the ' or '' or ''' quotes?
Thanks, S
  2 comentarios
nour brh
nour brh el 6 de Mzo. de 2023
Movida: Rik el 6 de Mzo. de 2023
how can i remove the 'quotes' ??
Rik
Rik el 6 de Mzo. de 2023
Movida: Rik el 6 de Mzo. de 2023
Those quote are not part of the data stored in your table. They are only there in the visualisation.So if you could remove them, the result would be to replace them with NaN.
I will move your answer to the comment section, since it actually isn't an answer.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 20 de Oct. de 2012
The single quotes aren't really there. That's just MATLAB's way of enclosing/displaying a string. To get rid of the double quotes,
strrep( YourArray(:,1),'"','');
  1 comentario
Matt J
Matt J el 21 de Oct. de 2012
Editada: Matt J el 21 de Oct. de 2012
Here's a more complete example,
E(:,1)={'a' '''b' 'c' '''d'}.';
E(:,2)={123, 456, 678,876}.';
E(:,1)=strrep(E(:,1),'''',''); %get rid of single quotes
E(:,1)=strrep(E(:,1),'"',''); %get rid of double quotes
%send to file
E=E.';
fid=fopen('events.txt','w');
for ii=1:numel(E)
if ischar(E{ii})
prec='%s';
else
prec='%d';
end
fprintf(fid,[prec '\t'],E{ii});
end
fclose(fid);

Iniciar sesión para comentar.

Más respuestas (1)

susan
susan el 21 de Oct. de 2012
Hi, That did not work..
How can I save this cell array (1159x2) to a text file (in the hopes that the quotes will not get saved)..
save('events','E','-ascii','-tabs') Warning: Attempt to write an unsupported data type to an ASCII file. Variable 'E' not written to file.
  3 comentarios
susan
susan el 21 de Oct. de 2012
Hi, Yes Sorry.. in my data the quotes seem to be introduced by the process sometime during save to .mat/text.. Can't retrace. And the quotes are not [' ''] but [''']. But I was able to get back the original data (i.e. with single quotes). I am however having trouble saving this to ascii format..
The original data is in this format
EEG.event
ans =
1x1159 struct array with fields: type latency urevent
EEG.event(1,1)
ans =
type: 'eyeo'
latency: 166124
urevent: 1
Then, E=struct2cell(EEG.event); E=[E(1,:) ; E(2,:)]';
It looks fine: 'TEND_b3_c' [645836] 'TSTRCo23_b3_c' [646153] 'Co23_b3_c' [646449] 'RTCo23_b3_c' [646655] 'TEND_b3_c' [646661]
save('Events','E','-ascii') Warning: Attempt to write an unsupported data type to an ASCII file. Variable 'E' not written to file.
Matt J
Matt J el 21 de Oct. de 2012
Did you see my solution above (the Comment to my original Answer)?

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings 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