how to automatically import multiple excel files, each contains 3D coordinates, into matlab?

2 次查看(过去 30 天)
I've 115 excel files each contains 3 columns named X, Y and Z.
Is it possible to import these data automatically, in a way that each X, Y and Z will be named X"filename", Y"filename" and Z"filename"??
Thank you very much for your help

回答(1 个)

Akiva Gordon
Akiva Gordon 2012-11-8
The naming model that you suggest is not really the best way to name your variables. Consider the following:
Get the list of files that end with ".xls",
files = dir('*.xls')
For each element in "files", read the Excel data of that file and define structure of x, y, & z
for i = 1:numel(files)
data = xlsread(files(i).name);
x.(files(i).name) = data(:,1);
y.(files(i).name) = data(:,2);
z.(files(i).name) = data(:,3);
end
Sorry I didn't get a chance to test this, so I hope this works for what you are trying to do. Also, if the files are sequentially numbered and the number of rows are the same in each file, you may want to consider storing the data in standard arrays (i.e. x(:,i)), rather than in structures.
  1 个评论
AAA
AAA 2012-11-12
Dear Akiva, Thank you very much for your answer. I've tried to use the command lines. it gave me the following: "files =
0x1 struct array with fields: name date bytes isdir datenum"
May be I need to give more description: I'm using matlab on a mac. the manual method that gave me the wanted results was as follows: 1. import data, 2. create vector from each column using column names. 3. renaming the X, Y, & Z, into X_filename, Y_filename, and Z_filename.
I'm looking for a method to do that to all the files automatically.
Thank you very much for your help.
Have a great day,

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by