MATLAB: How to append variables in a specific .mat file in a specific path

append data .mat

greeting
how to append variables in a specific .mat file in a specific path
[FileName,PathName] = uigetfile('*.mat','Select the Rotor DATA file')
FileName =
Data.mat
PathName =
C:\Users\PC\Desktop\
i need to add variabls to Data.mat using UI
plz help

Best Answer

matfile = fullfile(PathName, FileName);
save(matfile, 'NameOfVariableToAppend', '-append');
This will typically leave the other variables stored in the file in the same positions they already are in. If the variable to append already exists in the file then it would typically overwrite the existing block for that variable if the storage space required is no larger than it was before, but if the variable to append already exists in the file and the new version is larger then the existing storage block in the file would typically be marked as unused and the new version would be appended to the file. It is not documented as to whether the entire file might ever be rewritten to fill in "holes" if the file gets fragmented from these kinds of updates.
Note that if the variable already exists in the file, then the new data will replace the old data, rather than being added on to the end of it.