フィルターのクリア

Removing 'quotes' from a cell array

51 ビュー (過去 30 日間)
susan
susan 2012 年 10 月 20 日
移動済み: Rik 2023 年 3 月 6 日
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 件のコメント
nour brh
nour brh 2023 年 3 月 6 日
移動済み: Rik 2023 年 3 月 6 日
how can i remove the 'quotes' ??
Rik
Rik 2023 年 3 月 6 日
移動済み: Rik 2023 年 3 月 6 日
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.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2012 年 10 月 20 日
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 件のコメント
Matt J
Matt J 2012 年 10 月 21 日
編集済み: Matt J 2012 年 10 月 21 日
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);

サインインしてコメントする。

その他の回答 (1 件)

susan
susan 2012 年 10 月 21 日
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 件のコメント
susan
susan 2012 年 10 月 21 日
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 2012 年 10 月 21 日
Did you see my solution above (the Comment to my original Answer)?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by