Difficulties Extracting Header Info from .xlsx File in MATLAB 2020b
조회 수: 11 (최근 30일)
이전 댓글 표시
Whenever I try to run scripts that read tables with headers, it does not seem that the headers are read correctly.
I noticed this in two examples.
The first was a short script my colleague wrote to add characters into a text string using a defined column name. We imported the data into the workspace using the definition below but in my version, the headers were set as the first row and not identified as the header. An additional line was added to ReadVariableName which resulted in the headers showing as both the header line and row 1. This behavior had not been seen in my colleagues version (MATLAB 2019b)
datatable = readtable('FILE NAME.xlsx');
The second example is with another script that is importing information from a .xlsx file and a .csv file. The portion of code that I routinely get an error on is as follows
function AlignData(Run, Raman, Offline)
% Header Information
Headers = readtable(Offline.fileName,'sheet',Offline.sheet,'Range','C1:AA16','ReadVariableNames',false);
Lines = table2cell(Headers); Head= strcat(Lines(1,:), {' '}, Lines(2,:));
% Load data
ImportOptions = detectImportOptions(Offline.fileName,'sheet',Offline.sheet,...
'Range',Offline.range,'ReadVariableNames', true,'NumHeaderLines',0);
OfflineDataTable = readtable(Offline.fileName,ImportOptions);
I have seen the following errors:
Error using detectImportOptions (line 238)
Setting both Range and NumHeaderLines is not supported for this file type.
Error in AlignedUnits_Set10_Final>AlignData (line 24)
ImportOptions = detectImportOptions(Offline.fileName,'sheet',Offline.sheet,...
Error in AlignedUnits_Set10_Final (line 17)
AlignData(Run, Raman, Offline)
Error in AlignData (line 3)
Headers = readtable(Offline.fileName,'sheet',Offline.sheet,'Range','C1:AA2','ReadVariableNames',false);
I am unsure if there is a setting or an app that is different in my MATLAB as my colleagues are able to run the same script and files with no issues. I am a very new user so have not run any prior scripts within the software I have. The files are hosted right now on my corporate personal OneDrive which is similar to how my colleague also runs.
댓글 수: 0
채택된 답변
Namit Joshi
2022년 2월 1일
Hey,
This is a known issue in MATLAB R2020b. It has been fixed in R2021b and the subsequent releases. I suggest you to upgrade to the latest release of MATLAB for all the latest updates and bug fixes.
Hope this helps!
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!