Effacer les filtres
Effacer les filtres

Removing 'quotes' from a cell array

51 vues (au cours des 30 derniers jours)
susan
susan le 20 Oct 2012
Déplacé(e) : Rik le 6 Mar 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 commentaires
nour brh
nour brh le 6 Mar 2023
Déplacé(e) : Rik le 6 Mar 2023
how can i remove the 'quotes' ??
Rik
Rik le 6 Mar 2023
Déplacé(e) : Rik le 6 Mar 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.

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 20 Oct 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 commentaire
Matt J
Matt J le 21 Oct 2012
Modifié(e) : Matt J le 21 Oct 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);

Connectez-vous pour commenter.

Plus de réponses (1)

susan
susan le 21 Oct 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 commentaires
susan
susan le 21 Oct 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 le 21 Oct 2012
Did you see my solution above (the Comment to my original Answer)?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by