Clear Filters
Clear Filters

Removing 'quotes' from a cell array

51 views (last 30 days)
susan
susan on 20 Oct 2012
Moved: Rik on 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 Comments
nour brh
nour brh on 6 Mar 2023
Moved: Rik on 6 Mar 2023
how can i remove the 'quotes' ??
Rik
Rik on 6 Mar 2023
Moved: Rik on 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.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 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 Comment
Matt J
Matt J on 21 Oct 2012
Edited: Matt J on 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);

Sign in to comment.

More Answers (1)

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

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!