用MATLAB添加新列到Excel中

我想问如何使用MATLAB来追加新的列到现有的Excel文件,而不改变文件中的原始数据? 在我的情况下,我不知道文件中的原始列数和行数,并且逐个打开文件并在实践中检查是低效的。 另一个困难是新列可能与现有数据有不同的行数,所以我不能用数据读取的技巧,形成一个新的matrix,用新的matrix代替数据。

我已经看到很多post教人们如何添加新的行,但添加新的列似乎是完全不同的东西,因为列是用字母而不是数字命名的。

谢谢。

您可以尝试读取数据,使用数组的大小来确定列的数量,然后使用xlswrite和所需的范围。 在这里看看一个函数将列号转换为Excel格式: http : //au.mathworks.com/matlabcentral/answers/54153-dynamic-ranges-using-xlswrite

最后我用下面的代码解决它:

%%%

if(step == 1)xlswrite(filename,array,sheetname,'A1'); %创build文件else [〜,〜,Data] = xlsread(filename,sheetname); %读入所有旧数据

OriCol=size(Data,2); %get the column number of the old data NewCol=OriCol+1; %the new array is placed right next to the original data ColLetter=xlcolumnletter(NewCol); StartCell=[ColLetter,'1']; xlswrite(filename,array,sheetname,StartCell); 

结束