Converting string matrix from Excel to Matlab

I have an excel document containing a matrix of strings (that is, each cell contains a word of varying length). If possible, I want to read this into Matlab so that I have a matrix of strings just as it is in Excel. In particular, I need to be able to reference the (i,j)th matrix element, which should contain an individual word/string.
For example, if cell A2 in excel contains "dog," I would like element (1,2) in matlab to contain the string 'dog'.
It seems like there should be a quick way to do this, but I can't get anything to work. Does anyone have any ideas? Let me know, thanks!!

 채택된 답변

Laura Proctor
Laura Proctor 2011년 4월 12일

0 개 추천

Use XLSREAD with three outputs. The final output, raw, will contain a cell array with all of your data from Excel.
[num,txt,raw] = xlsread(filename)
A2 = raw{1,2}; % Will assign the element to variable A2

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 4월 12일

0 개 추천

If you are on a Windows machine and have Excel installed, then xlsread() should be able to return the data in the form of cell arrays. You would need to use element{1,2} instead of element(1,2) but that adjustment should not be difficult.

댓글 수: 1

John
John 2011년 4월 12일
Unfortunately I'm working on a mac laptop. Is there any way to do this with a mac?

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

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

질문:

2011년 4월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by