Reading a string with %
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to read in a list of strings from a .xls file, some of which contain a %. Since this is generally used to add comments to a block of code, the stings that contain %'s are being read into MATLAB as ''. Is there any way to read these strings into MATLAB so that they include the %? For example
'hello%mynameis'
, or should I just scrap them from my list?
Many Thanks, Charlie
1 个评论
采纳的回答
Guillaume
2014-10-13
Could you show the portion of code you're using to read your excel file?
The first output of xlsread is only the numeric content of the Excel file. However, you should be able to extract your string from the second or third output. That is, if all you're doing is:
data = xlsread('somefile.xlsx');
now do:
[data, text, raw] = xlsread('somefile.xlsx');
更多回答(1 个)
dpb
2014-10-13
You don't give any other information on what you tried, but there's no reason you can't read such strings into Matlab...
>> l='hello%mynameis';
>> textscan(l,'%s')
ans =
{1x1 cell}
>> ans{1}
ans =
'hello%mynameis'
>>
What specific file format did you have and what specific problem did you have with reading it with what specific statement/function?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!