Need help understanding xlswrite function

조회 수: 2 (최근 30일)
Brian Nguyen
Brian Nguyen 2021년 10월 1일
댓글: Walter Roberson 2021년 10월 1일
Hello,
I am trying to convert a cell matrix that contains individual words of a sentence into an excel spreadsheet. Each sentence has varying number of words, but empty cells are placed to retain proper amount of columns. For some reason, the function of xlswrite creates a spreadsheet that is blank and I do not understand why. Attached is the cell matrix and its coresponding excel sheet to help orient what the problem looks like. Also, I do see that the excel file highlights the range of the cell matrix, but there are no contents. Furthermore, I am using MATLAB2015a
Thanks!
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2021년 10월 1일
@Brian Nguyen - please post the code that you are using to write the data (from the mat file) to the Excel spreadsheet.

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 10월 1일
Your Sentence_list is a cell array that contains cell arrays.
SL = arrayfun(@(C) C{1}, Sentence_list);
xlswrite('Score_sheet.xls', SL)
  댓글 수: 2
Brian Nguyen
Brian Nguyen 2021년 10월 1일
Hello! So this works, but I am confused how. Does arrayfun() acess each element of the cell array?
Walter Roberson
Walter Roberson 2021년 10월 1일
A cell array is a kind of array, so arrayfun can access the elements. The elements are cell arrays, that in this case happen to store cell arrays. C{1} is pulling out the inner cell array.
You might possibly be able to instead use
SL = cellfun(@(C) C, Sentence_list) %notice the lack of 'uniform', 0

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

추가 답변 (0개)

카테고리

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