[英]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.