Importing Excel Database Into MATLAB

5 visualizzazioni (ultimi 30 giorni)
Selim Elbadri
Selim Elbadri il 9 Dic 2022
Commentato: Voss il 11 Dic 2022
Hi,
I have an excel dataset 'dataset2' which I want to import into MATLAB. I will then perform some matrix manipulations. I am running the code below but it does not seem to be doing exactly what I want:
clc
clear all
cd 'C:\XXXX'
test = readtable('./dataset2.xlsx','Sheet','Sheet1','Range','A2:CA26','TreatAsEmpty',{'.'},'Format','auto');
For some reason, the second row was taken as variable names and not the first. I don't know what happened to the first row. How can I fix this such that only the first row is considered the variable name/header?
Thank you!

Risposta accettata

Voss
Voss il 9 Dic 2022
The problem is that you're specifying the Range to start on row 2. Remove the Range arguments:
test = readtable('./dataset2.xlsx', ...
'Sheet','Sheet1', ...
...'Range','A2:CA26', ...
'TreatAsEmpty',{'.'}, ...
'Format','auto');
disp(test)
RNr a_vAUS28 a_vAUS29 a_vAUS30 a_vAUS31 a_vAUS32 a_vAUS33 a_vAUS34 a_vAUS35 a_vAUS36 a_vAUS37 a_vAUS38 a_vAUS39 a_vAUS40 a_vAUS41 a_vAUS42 a_vAUS43 a_vAUS44 a_vAUS45 a_vAUS46 a_vAUS47 a_vAUS48 a_vAUS49 a_vAUS50 a_vAUS51 a_vAUS52 id ind_1_i ind_2_i ind_3_i ind_4_i ind_5_i ind_6_i ind_7_i ind_8_i ind_9_i ind_10_i ind_11_i ind_12_i ind_13_i ind_14_i ind_15_i ind_16_i ind_17_i ind_18_i ind_19_i ind_20_i ind_21_i ind_22_i ind_23_i ind_24_i ind_25_i e_vector ec_vector ind_1 ind_2 ind_3 ind_4 ind_5 ind_6 ind_7 ind_8 ind_9 ind_10 ind_11 ind_12 ind_13 ind_14 ind_15 ind_16 ind_17 ind_18 ind_19 ind_20 ind_21 ind_22 ind_23 ind_24 ind_25 ___ __________ _________ __________ __________ __________ __________ __________ __________ __________ _________ __________ __________ _________ __________ __________ __________ __________ _________ ________ ________ ________ ________ _________ _________ __________ __ _______ _______ _______ _______ _______ _______ _______ _______ _______ ________ ________ ________ ________ ________ ________ ________ ________ ________ ________ ________ ________ ________ ________ ________ ________ ________ _________ _______ _______ ______ _______ ______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ ______ ______ ______ ______ _______ _______ _______ 28 0.0010661 0.0086166 0.011514 0.046485 0.011402 0.0019305 0.016032 0.01445 0.0016091 0.0051013 0.0030389 0.014035 0.0036651 0.00046417 0.00023188 0.00030533 0.0014186 0.0032941 0 0 0 0 0.0075036 0.0028969 0.00086978 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2669.9 2668.6 0.32944 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 29 0.083806 0.021775 0.016656 0.040204 0.017705 0.032528 0.012003 0.034374 0.037409 0.010128 0.019797 0.02894 0.014489 0.0017971 0.00064889 0.00077506 0.004389 0.012087 0 0 0 0 0.013605 0.01235 0.016888 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18271 13428 0 0.44808 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 0.014286 0.010422 0.01109 0.01706 0.0055564 0.0082788 0.0074796 0.011411 0.014948 0.0046424 0.0078812 0.0096212 0.0042177 0.0012371 0.00036031 0.00047073 0.0018144 0.0038626 0 0 0 0 0.0063861 0.0040625 0.0051933 3 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25340 24296 0 0 0.5629 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 31 0.0045378 0.0099685 0.0049521 0.027317 0.0061963 0.0065567 0.010462 0.0098918 0.011058 0.0051275 0.0038813 0.0086592 0.0030523 0.00055429 0.00028034 0.00053917 0.0011443 0.0032298 0 0 0 0 0.0046817 0.0064894 0.0043905 4 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4320.6 3894.6 0 0 0 0.43962 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 0.00039033 0.001749 0.00079191 0.0003452 0.14269 0.0011335 0.00042608 0.0029603 0.0011987 0.0010061 0.00011557 0.0028754 0.0025942 0.00019692 6.4793e-05 4.8131e-05 0.00048564 0.003111 0 0 0 0 0.0022937 0.001948 0.00081663 5 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3.1324 2.8636 0 0 0 0 0.3835 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0.00221 0.016895 0.007648 0.0026093 0.0078314 0.023875 0.010656 0.016845 0.0040437 0.009051 0.0097498 0.016216 0.013498 0.0027181 0.0017121 0.002863 0.0013234 0.023685 0 0 0 0 0.018315 0.016345 0.0080661 6 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 248.01 128.89 0 0 0 0 0 0.31221 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 34 0.0068609 0.075441 0.0075602 0.012076 0.13654 0.064763 0.050445 0.0058028 0.0021253 0.022636 0.0022 0.0056182 0.00557 0.0011356 0.00036095 0.00011293 0.0024564 0.0094773 0 0 0 0 0.018825 0.011702 0.0031764 7 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 937.03 875.94 0 0 0 0 0 0 0.46845 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 35 0.0071531 0.007782 0.0081536 0.0073833 0.0008902 0.0016808 0.006163 0.030357 0.0054666 0.0082686 0.0049191 0.012297 0.0066874 0.002009 0.0018096 0.0038792 0.00081929 0.010963 0 0 0 0 0.0072771 0.0058083 0.0046366 8 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.8202 0.30362 0 0 0 0 0 0 0 0.46041 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0.0019121 0.0085154 0.004225 0.003308 0.0021618 0.0052064 0.0069055 0.0075769 0.0016881 0.0096628 0.0062111 0.0072593 0.0052885 0.0022137 0.00097316 0.001292 0.00092078 0.011731 0 0 0 0 0.010012 0.0064175 0.0029907 9 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18756 18732 0 0 0 0 0 0 0 0 0.40473 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0.0037325 0.0069648 0.011032 0.0013403 0.00077373 0.0014753 0.0025023 0.0092767 0.0032375 0.0093556 0.0052118 0.0092315 0.012274 0.00076858 6.0584e-05 0.00019749 0.0031075 0.011911 0 0 0 0 0.0089415 0.0050869 0.018469 10 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2224.6 1837.5 0 0 0 0 0 0 0 0 0 0.53816 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 38 0.0012865 0.0022148 0.0062094 0.00068735 0.00099376 0.0016926 0.0013236 0.0013609 0.025182 0.068951 0.19933 0.0021938 0.012839 0.0022783 0.00030057 0.00031131 0.0030657 0.012988 0 0 0 0 0.012977 0.0023286 0.0014258 11 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1014.6 610.1 0 0 0 0 0 0 0 0 0 0 0.42883 0 0 0 0 0 0 0 0 0 0 0 0 0 0 39 0.018829 0.023771 0.023678 0.0093996 0.0044733 0.0065403 0.030715 0.017003 0.011807 0.0064045 0.018963 0.017289 0.017297 0.004785 0.0014971 0.007749 0.0052158 0.024141 0 0 0 0 0.016192 0.020345 0.01241 12 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 6265.5 5426.9 0 0 0 0 0 0 0 0 0 0 0 0.46383 0 0 0 0 0 0 0 0 0 0 0 0 0 40 0.0028302 0.018322 0.0087614 0.0036136 0.0044319 0.004537 0.0080713 0.012516 0.0050527 0.0061306 0.0057787 0.041923 0.07848 0.0079341 0.012579 0.0093529 0.0025976 0.032046 0 0 0 0 0.023702 0.055041 0.014254 13 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 4677.1 1055.6 0 0 0 0 0 0 0 0 0 0 0 0 0.53483 0 0 0 0 0 0 0 0 0 0 0 0 41 0.01217 0.023112 0.014422 0.010783 0.020457 0.010794 0.026403 0.010609 0.0092554 0.0090157 0.01425 0.012892 0.0078582 0.022229 0.066994 0.0045956 0.10962 0.02161 0 0 0 0 0.023804 0.010605 0.0093373 14 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 10373 10337 0 0 0 0 0 0 0 0 0 0 0 0 0 0.68638 0 0 0 0 0 0 0 0 0 0 0 42 0.015373 0.0053588 0.0051739 0.0021801 0.00038545 0.000344 0.0016119 0.0017888 0.0065113 0.0086108 0.006397 0.0017108 0.0026838 0.0019425 0.00043492 0.00144 0.0041193 0.0034229 0 0 0 0 0.0045935 0.001528 0.00056212 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 12147 12103 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.63999 0 0 0 0 0 0 0 0 0 0 43 0.005349 0.00417 0.0023993 0.001057 0.00040086 0.0007485 0.0011666 0.0060436 0.0016542 0.0011495 0.0017602 0.0063062 0.0012227 0.19646 0.21311 0.16523 0.00094442 0.0058771 0 0 0 0 0.0024313 0.032573 0.0016632 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1031.4 1014.1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.73492 0 0 0 0 0 0 0 0 0 44 0.002011 0.060014 0.025535 0.0215 0.0043954 0.022116 0.0379 0.042299 0.020868 0.0031982 0.020329 0.040879 0.012241 0.014277 0.018003 0.0047754 0.055811 0.019538 0 0 0 0 0.074187 0.0041811 0.0032416 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 36148 34057 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.65156 0 0 0 0 0 0 0 0 45 0.04819 0.046089 0.053854 0.028723 0.020489 0.027539 0.046399 0.01387 0.022321 0.026971 0.031585 0.020528 0.089917 0.0038935 0.0036455 0.022877 0.034845 0.14111 0 0 0 0 0.052487 0.030747 0.0091054 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 5916.4 973.35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.43663 0 0 0 0 0 0 0 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 50 0.027279 0.023988 0.036413 0.010269 0.010147 0.096109 0.08032 0.023419 0.052592 0.085338 0.021994 0.021545 0.029713 0.010197 0.0064994 0.018262 0.026497 0.043945 0 0 0 0 0.064736 0.02332 0.018333 23 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1209.2 1198.1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.47537 0 0 51 0.008486 0.0046323 0.0045147 0.011564 0.0014474 0.0010147 0.019616 0.010228 0.0022712 0.014199 0.0070896 0.010658 0.014347 0.00069585 0.00040194 0.001119 0.002749 0.017078 0 0 0 0 0.010685 0.027264 0.0067314 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 817.05 614.34 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.56358 0 52 0.0035653 0.0010284 0.0010699 0.0010424 0.00059326 0.00093215 0.0030838 0.00072262 0.00098229 0.0009026 0.0012414 0.00080937 0.0043978 0.0025197 0.00060875 0.0018078 0.00095667 0.0065512 0 0 0 0 0.0046596 0.0026175 0.0071311 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 8486.9 8418.2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.73377
In fact, for this particular file, you get the same result without specifying any Name,Value argument pairs (i.e., using all defaults):
test2 = readtable('./dataset2.xlsx');
isequal(test,test2) % same as above
ans = logical
1

Più risposte (2)

Jon
Jon il 9 Dic 2022
I just ran
T = readtable('dataset2.xlsx')
and it seems to import without any problems

Jeremy Hughes
Jeremy Hughes il 9 Dic 2022
This issue is in the call to readtabkle
test = readtable('./dataset2.xlsx','Sheet','Sheet1','Range','A2:CA26','TreatAsEmpty',{'.'},'Format','auto');
In this call Range has a starting cell of A2, which means it starts on the second row. From there, it assumes the first row is variable name, Also, format=auto is probably not needed, if it works without it, that would be best.
test = readtable('./dataset2.xlsx','Sheet','Sheet1','Range','A1:CA26','TreatAsEmpty',{'.'});

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by