Reading a string with %

조회 수: 3 (최근 30일)
Charlotte
Charlotte 2014년 10월 13일
댓글: Charlotte 2014년 10월 13일
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
Jan
Jan 2014년 10월 13일
편집: Jan 2014년 10월 13일
Please post your current code. Why do you assume that the % characters are not imported? Did you check this by something like this:
s = 'hello%mynameis'
fprintf(s)
Then try:
fprintf('%s', s)

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
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');
  댓글 수: 2
Charlotte
Charlotte 2014년 10월 13일
I have been using the second method you suggested. Here is my code when I read the data into MATLAB:
[num2, txt2, raw2] = xlsread('MasterList.xlsx', 'Sheet1', 'C2:C50'); wikiNames = txt2;
Is this correct? Also what about other strings that contain other weird symbols like Æterna_Zentaris? Will this method work for these as well?
Charlotte
Charlotte 2014년 10월 13일
I just implemented this method in MATLAB and it worked great for all symbols. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

dpb
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?
  댓글 수: 1
Charlotte
Charlotte 2014년 10월 13일
The file is a .xls file and I have been attempting to read in the data using xlsread since some of the data are dates and some of the data are strings. If I remember correctly, textscan does not work for excel files?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by