can xlsread read everything as strings ? if not, are there any other options ?

조회 수: 7 (최근 30일)
Elina
Elina 2014년 11월 25일
댓글: John 2015년 4월 27일
it seems xlsread will distinguish between numbers and strings, thus unable to read EVERYTHING as strings. am i correct? If so, i can only think of using actxserver and reading the content cell-by-cell. However, it requires that the cell displays the full content, that is, it cannot display something like '#####' which is what you'll see in excel if the number is too long. is there any easier option ? thanks so much
  댓글 수: 1
Guillaume
Guillaume 2014년 11월 25일
편집: Guillaume 2014년 11월 25일
Your premise is wrong. What is displayed in the cell by excel in no way prevents you from reading the full content of the cell. The two are completely independent.
What is displayed is the Text property of the Range object, the value of the cell is the value property of the Range object.

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

답변 (2개)

Hikaru
Hikaru 2014년 11월 25일
Have you tried using the command:
[~,~,RAW]=xlsread('filename')
The variable raw will contain everything, if I'm not mistaken.
  댓글 수: 2
Elina
Elina 2014년 11월 25일
thanks. sorry, it is not EVERYTHING as STRINGS: Still NUMBERS saved as NUMBERS and STRINGS saved as STRINGS. e.g. suppose an excel cell reads as a number 999,999 if i use xlsread, it will be saved as a number 999999 in a matlab cell. However, what i want in the cell is '999,999' which is a string in the cell.
John
John 2015년 4월 27일
I'm having the same problem. I have a string "2E10" which is being read in as 2.00E10.

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


Guillaume
Guillaume 2014년 11월 25일
Note that it is excel returning numbers as numbers and text as text (xlsread uses actxserver behind the scene), so if you want numbers as strings, you'll have to do the conversion yourself:
[~, ~, raw] = xlsread('somefile');
for idx = 1:numel(raw)
if isnumeric(raw{idx})
raw{idx} = num2str(raw{idx});
end
end

카테고리

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