简体   繁体   English

如何从电子表格导入大量数据到Matlab中?

[英]How to import lots of data into matlab from a spreadsheet?

I have an excel spreadsheet with lots of data that I want to import into matlab. 我有一个Excel电子表格,其中包含很多要导入到matlab中的数据。

filename = 'for_matlab.xlsx';
sheet = (13*2)+ 1;
xlRange = 'A1:G6';
all_data = {'one_a', 'one_b', 'two_a', 'two_b', 'three_a', 'three_b', 'four_a', 'four_b', 'five_a', 'five_b', 'six_a', 'six_b', 'seven_a', 'seven_b', 'eight_a', 'eight_b', 'nine_a', 'nine_b', 'ten_a', 'ten_b', 'eleven_a', 'eleven_b', 'twelve_a', 'twelve_b', 'thirteen_a', 'thirteen_b', 'fourteen_a'};

%read data from excel spreadsheet
for i=1:sheet,
    all_data{i} = xlsread(filename, sheet, xlRange);
end

Each element of the 'all_data' vector has a corresponding matrix in separate excel sheet. “ all_data”向量的每个元素在单独的Excel工作表中都有一个对应的矩阵。 The code above imports the last matrix only into all of the variables. 上面的代码仅将最后一个矩阵导入所有变量中。 Could somebody tell me how to get it so I can import these matrices into individual matlab variables (without calling the xlsread function 28 times)? 有人可以告诉我如何获得它,以便可以将这些矩阵导入到单独的matlab变量中(无需调用xlsread函数28次)吗?

You define a loop using i but then put sheet in the actual xlsread call, which will just make it read repeatedly from the same sheet (the value of the variable sheet is not changing). 您可以使用i定义一个循环,然后将工作sheet放入实际的xlsread调用中,这只会使它从同一工作表中重复读取(变量工作sheet值没有改变)。 Also not sure whether you intend to somehow save the contents of all_data , as written there's no point in defining it that way as it will just be overwritten. 同样也不确定您是否打算以某种方式保存all_data的内容,就这样写它没有意义,因为它将被覆盖。

There are two ways of specifying the sheet using xlsread . 使用xlsread指定工作表有两种方法。

1) Using a number. 1)使用数字。 If you intended this then: 如果您打算这样做,则:

all_data{i} = xlsread(filename, i, xlRange);

2) Using the name of the sheet. 2)使用工作表名称。 If you intended this and the contents of all_data are the names of sheets, then: 如果您打算这样做并且all_data的内容是all_data表的名称,则:

data{i} = xlsread(filename, all_data{i}, xlRange); %avoiding overwriting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用循环的情况下有条件地将数据从电子表格导入MATLAB - How to conditionally import data from a spreadsheet into MATLAB without using a loop 从SQL Server和另一个Excel电子表格将数据导入Excel电子表格 - Import data into an Excel spreadsheet from SQL Server and another Excel Spreadsheet 从Web可导出电子表格导入数据 - Import Data from Web Exportable Spreadsheet 将数据从已发布的Google电子表格导入到Excel - Import data from published Google spreadsheet to Excel 将数据从excel电子表格导入django模型 - Import data from excel spreadsheet to django model 如何从Excel中的表格中删除过滤器,该表格是由DataTable函数中的电子表格轻导入数据创建的。 - How to remove filter from table in excel created by spreadsheet-light import data from a DataTable function. 您通常如何将数据从电子表格导入多个数据库列? - How do you typically import data from a spreadsheet to multiple database columns? 如何从 Excel 电子表格中导入数据,以便在 C# 中对其进行操作 - How to import the data from an Excel spreadsheet so it can be manipulated in C# 将数据从Excel逐行导入到MATLAB - Import data from excel to matlab row by row For循环和Matlab数据从matfile导入 - For loop and Matlab data Import from matfile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM