【发布时间】:2021-06-03 15:04:20
【问题描述】:
每次执行某些函数时,我都会将结果存储在 Excel 文件中。第一列的行包含每个主题的唯一 ID。每当我执行该函数时,新结果都会自动附加到新行中。每当执行相同的信息时,我想用警告标志覆盖包含唯一 ID 信息的行,例如“信息已经存在,你想覆盖它们吗”等。我在 matlab 中使用“唯一”函数尝试了这个,但没有成功。非常感谢这方面的任何帮助。
到目前为止我的代码如下:
LastName = {'Sam';'John';'Bella';'Diana';'Kelly'};
Age = [48;53;58;80;29];
Smoker = logical([1;0;1;0;1]);
Height = [61;59;64;69;62];
Weight = [126;153;141;153;129];
BloodPressure = [104 95; 119 79; 115 85; 127 85; 112 81];
Table = table(LastName,Age,Smoker,Height,Weight,BloodPressure)
writetable(Table,"BP_Analysis.xlsx","WriteMode","append","AutoFitWidth",false);
%Overwirte the rows "Lastname" if same results are executed again.
data = readtable('BP_Analysis.xlsx','PreserveVariableName', true);
data.Properties.VariableNames{1} = 'Lastname';
[~,idx]=unique(strcat('Lastname','rows'));
如果再次执行具有相同姓氏的数据,我想覆盖任何行中的所有信息。我创建了一个虚拟问题来反映我的原始数据。
【问题讨论】: