Getting error message "Index exceeds the number of array elements. Index must not exceed 0."

조회 수: 3 (최근 30일)
T = readtable("Data.xlsx");
data = readtable('Data.xlsx','TextType','string');
textData = data.Properties.Description;
textData(1:10)
cleanedDocuments = tokenizedDocument(textData);
cleanedDocuments(1:10)
cleanedDocuments = addPartOfSpeechDetails(cleanedDocuments);
cleanedDocuments = removeStopWords(cleanedDocuments);
cleanedDocuments(1:10)
cleanedDocuments = normalizeWords(cleanedDocuments,'Style','lemma');
cleanedDocuments(1:10)
cleanedDocuments = erasePunctuation(cleanedDocuments);
cleanedDocuments(1:10)
cleanedBag = bagOfWords(cleanedDocuments);
cleanedBag = removeInfrequentWords(cleanedBag,2);
[cleanedBag,idx] = removeEmptyDocuments(cleanedBag);
labels(idx) = [];
cleanedBag;
  댓글 수: 3
the cyclist
the cyclist 2023년 9월 9일
Thousands of data points in an Excel file is not too many to upload, and that's the fastest way for us to help you.
You could also just upload a few rows of the file, if that gives the same error. (If that does not give the same error, then you've taken a step toward debugging the problem.)
Also, which line gives that error?

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

답변 (2개)

Walter Roberson
Walter Roberson 2023년 9월 9일
편집: Walter Roberson 2023년 9월 9일
readtable() by default uses detectImportOptions or one of its variations. For an xlsx file, a spreadsheetImportOptions object would get created. That kind of import options object has no property that can control where to look in the xlsx file to find information to store in the table Description property
readtable() in turn has no option to indicate where to look to find information to store in the table Description property.
Which is to say that the table property 'Description' is initialized to empty. But your code expects that it has at least 10 elements to it.
There is a property with a related name, data.Properties.VariableDescriptions which potentially contains a description for each variable. The VariableDescriptions property can be set by readtable() under at least some conditions. Conditions have to be just right for automatic detection of variable descriptions.... That or the detected variable names have to include at least one variable name that is not a valid MATLAB identifier: in that case the default is to generate valid MATLAB variable names for the columns and to write the detected variable names into the VariableDescriptions property...
Note that data.Properties.Description is not the same as data.Description -- which would be what would be used if you had a variable whose name was Description .

david cowan
david cowan 2023년 11월 19일
[cleanedBag,idx] = removeEmptyDocuments(cleanedBag);
labels(idx) = [];
no empty documents?
labels not same size as cleanedBag?

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by