Filter löschen
Filter löschen

Removing 'quotes' from a cell array

51 Ansichten (letzte 30 Tage)
susan
susan am 20 Okt. 2012
Verschoben: Rik am 6 Mär. 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 Kommentare
nour brh
nour brh am 6 Mär. 2023
Verschoben: Rik am 6 Mär. 2023
how can i remove the 'quotes' ??
Rik
Rik am 6 Mär. 2023
Verschoben: Rik am 6 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 20 Okt. 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 Kommentar
Matt J
Matt J am 21 Okt. 2012
Bearbeitet: Matt J am 21 Okt. 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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

susan
susan am 21 Okt. 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 Kommentare
susan
susan am 21 Okt. 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 am 21 Okt. 2012
Did you see my solution above (the Comment to my original Answer)?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by