Why does ImportData transpose my entire excel file?
Ältere Kommentare anzeigen
I have a moderately large Excel file and all of my variable names are in the first column. ImportData only offers the option of variable names in rows, so I transposed the entire Excel file and saved it under a new name. In that Excel file, all the variable names are in the first row.
When I try to use "Import Data", the spreadsheet shows up transposed so again, all of my variable names are in the first column. Why did it transpose the entire Excel file?
TIA.
Kelly Cox
6 Kommentare
Ganesh
am 13 Jun. 2022
Could you please share the code for doing both these operations so it could be more clear
Kelly cox
am 13 Jun. 2022
Benjamin Thompson
am 13 Jun. 2022
Can you post all or part of the Excel file, and maybe the script that the Import Data tool would generate if you use the "Import Selection" button on the toolstrip to generate MATLAB code for the import process?
Kelly cox
am 13 Jun. 2022
dpb
am 13 Jun. 2022
num=xlsread('MatlabATImport.xlsx');
I'd venture you got the same file both times/ways with the import tool -- or there's some other structure/data in the file that still confused its internal algorithm about how it tries to interpret the file. It won't transpose willy-nilly although. While importdata is an easy function to use from the standpoint of needing no thinking about the file content to dispatch it; as you (and many others) have learned; that comes at the price of not necessarily getting what you think you're going to get -- it has to try to figure out the content on its own and do its best to interpret what is in the file. Given spreadsheet files can be arbitrary in their content and arrangement, it's simply not possible to always figure out what the user may intend.
The short answer is, "if it matters what the format is, then don't use a free format input tool". Albeit, TMW doesn't make any of this at all clear in the training or introductory documentation; they make it sound as though it is true magic -- it may be close, but not quite.
I'd strongly follow in TMW's footsteps, however, and recomend against falling into the habit of using the old and deprecated xlsread/xlswrite functions, however, also. Use readtable, readcell, readmatrix... family instead.
Antworten (0)
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!