![](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!