Reading a string with %

3 Ansichten (letzte 30 Tage)
Charlotte
Charlotte am 13 Okt. 2014
Kommentiert: Charlotte am 13 Okt. 2014
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 Kommentar
Jan
Jan am 13 Okt. 2014
Bearbeitet: Jan am 13 Okt. 2014
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)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Guillaume
Guillaume am 13 Okt. 2014
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 Kommentare
Charlotte
Charlotte am 13 Okt. 2014
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 am 13 Okt. 2014
I just implemented this method in MATLAB and it worked great for all symbols. Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

dpb
dpb am 13 Okt. 2014
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 Kommentar
Charlotte
Charlotte am 13 Okt. 2014
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?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by