Why does ImportData transpose my entire excel file?

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
Ganesh am 13 Jun. 2022
Could you please share the code for doing both these operations so it could be more clear
Hi Ganesh--there is no code. None at all. I simply click the ImportData tool. I select my Excel file, and the Import window opens.
Kelly cox
Kelly cox am 13 Jun. 2022
Bearbeitet: Jan am 13 Jun. 2022
To be more clear, I am trying to follow the instructions given by this Matlab instructor, who begins by using ImportData
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?
I figured it out with help from one of the Matlab answers. This code works for me:
>> num=xlsread('MatlabATImport.xlsx');
>> V1=num(2,:);
Feel free to close this question!
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Produkte

Version

R2017b

Gefragt:

am 13 Jun. 2022

Kommentiert:

dpb
am 13 Jun. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by