因此,您可以执行以下操作,但请注意,eval
不建议动态命名变量和使用:
my_command_string = [chosenTabs{i},'=readtable(inputFile,''Sheet'',chosenTabs{i})'];
eval(my_command_string);
如果我在编码:
我可能只是把它写出来(除非有很多......):
tab_Screen = readtable(inputFile,'Sheet','Screen');
tab_SectorAbsolute = readtable(inputFile,'Sheet','SectorAbsolute');
如果有吨和吨...
利用结构,excaza 在这个答案中建议的一个看起来很漂亮。其他一些方法是:
方法一:
n_chosenTabs = length(chosenTabs);
chosenTabs_data = cell(n_chosenTabs, 1);
for i=1:n_chosenTabs
chosenTabs_data{i} = readtable(inputFile,'Sheet',chosenTabs{i});
end
方法二:
您还可以使用containers.Map从选项卡名称转到实际表。加载地图:
tab_map = containers.Map;
for i=1:n_chosenTabs
tab_map(chosenTabs{i}) = readtable(inputFile,'Sheet',chosenTabs{i});
end
然后你可以使用类似的东西访问单个表。
local_copy_of_sector = tab_map('Sector');
请注意,如果您更改local_copy_of_sector
它不会更改存储在容器中的副本。地图;