Variables name changed when import Excel datas into Matlab

Hello,
I tried to imported a large amount of data from Excel to Matlab but for some reason the variable name got changed to nAN, Anyone know how to keep the original variable name?
For example: My variables name in Excel are Current, Voltage, max output and then it all changed to nAN after got imported to Matlab

댓글 수: 3

Which release are you using? How are you doing the importing?
what happens if you try ?
T = readtable('YourFile.xlsx', 'ReadVariableNames', true);
the realease version I'm using is R2020b but I'm using your piece of command T = readtable('YourFile.xlsx', 'ReadVariableNames', true); And it still not working. Do you have any suggestions I can try? Thank you
This pic is after imported the data in Matlab
This pic is from Excel

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

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 2월 6일
I'd try something like this.
readtable("sampleTable.xlsx","VariableNamingRule","preserve","NumHeaderLines",1)
In R2020b, MATLAB is able to detect that row 3 is not part of the data, and will skip it.

댓글 수: 1

If you want to capture the descriptions (row 1) and the units (row 3) along with the variable names (row 2), you can do the following.
opts=detectImportOptions("sampleTable.xlsx");
opts.VariableDescriptionsRange=1;
opts.VariableNamesRange=2;
opts.VariableUnitsRange=3;
opts.PreserveVariableNames=true;
data=readtable("sampleTable.xlsx",opts)
data = 3x4 table
Curent Voltage Max output Vol Max output Cur ______ _______ ______________ ______________ 1.2 12.6 12.6 1.3 1.3 12.5 12.6 1.3 1.2 12.4 12.6 1.3
% View the table description and unit properties
data.Properties.VariableDescriptions
ans = 1x4 cell array
{'Raw data'} {'Raw data'} {'Raw data'} {'Ras data'}
data.Properties.VariableUnits
ans = 1x4 cell array
{'A'} {'V'} {'V'} {'A'}
If you are unfamiliar with how to access data in a MATLAB table, see this page.

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

카테고리

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

질문:

2021년 2월 6일

댓글:

2021년 2월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by