![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1315610/image.png)
Removing 'quotes' from a cell array
51 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!