问题描述
我想要做的很简单: 给定一个 excel 数据集和用户定义的输入,打开关联的 excel 文件,为用户输入的信息提取关联信息,并将这些信息保存在单独的 excel 文件中。
我已经开发了一个值列表,程序通过相关检查识别用户输入。我一直坚持让 Matlab 使用这些信息来打开正确的数据集,我不知道如何让 Matlab 以静默打开方式在 excel 中拉出一行/列,我不知道如何让它保存将该数据放入单独的 excel 文件中。任何帮助将不胜感激,谢谢。
解决方法
如果您有最新的 MATLAB(任何比 R2013b 更新的版本),请考虑使用函数 readtable
和 writetable
。 readtable
函数将“静默”地将 Excel 文件中特定工作表中的数据读取到 MATLAB table
变量中。从那里,您可以将表“查询”到 find the specific rows you want 并将结果写入带有 writetable
的新 Excel 表。
使用 readtable
,您可以使用参数 sheet
和 range
指定数据范围。
requested_data = readtable(excel_file,...
'sheet',input_sheet_name,...
'range',input_data_range);
并使用
将数据写入另一个Excel文件writetable(requested_data,ouput_excel_file,...
'sheet',output_sheet_name,...
'range',output_data_range);
注意:记得在上面运行之前设置excel_file
、input_sheet_name
、input_data_range
、output_excel_file
、output_sheet_name
和output_data_range
的值命令。
查询表到access data in your table。一种方法是在 ismember
答案中使用 this。
最后,使用 writetable
存储值。
另见:sheetnames
、detectImportOptions
和 SpreadsheetImportOptions