Difficulties Extracting Header Info from .xlsx File in MATLAB 2020b

4 ビュー (過去 30 日間)
Victoria Berger
Victoria Berger 2022 年 1 月 21 日
回答済み: Namit Joshi 2022 年 2 月 1 日
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.

採用された回答

Namit Joshi
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 件)

カテゴリ

Find more on File Operations in Help Center and File Exchange

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by