Append a file, Error using save, File may be corrupt
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am attempting to append either a cell or structure to a file, I have tried both, to either an .xlsx or .mat file, I have tried both.
data = uigetfile('*.mat');
s = load(data);
date = regexp(data, '\d+_\d+', 'match');
file = (s.details);
% Comment on data
comment = 'NaN';
% Create cell
IAMHS_f = [date comment file(1,1) file(1,2) file(1,3) file(1,4)];
% Create stucture
% headings = {'Date' 'Comments' 'Mean' 'Min' 'Max' 'Std'};
% IAMHS_f2 = cell2struct(IAMHS_f,headings, 2)
%%Save and append parameter
savdir = 'C:\Users\Tim\Documents\AI-LLC\DATA\2ndary\DailyDetails\FinalPlots'
save(fullfile(savdir,'IAMHS.mat'),'IAMHS_f','-append')
The files I have tried appending are empty .mat and .xlsx files. When I do so I get (Error using save, File may be corrupt)
I have also tried saving one set of data first and then doing an append feature and it appears like it overwrites the existing data. I would prefer to be able to save the first set of data without having to make any adjustments to my code to append it.
I essentially have a 1x6 (cell or structure) and want to save it and continue adding rows.
0 Commenti
Risposta accettata
dpb
il 28 Lug 2015
Modificato: dpb
il 29 Lug 2015
As the English definition implies, "append" means there's got to be something already there to append to. While computer-language definitions don't always have a direct correlation to the equivalent word in common usage, it appears that is the case with save.
>> dir x.*
'x.*' not found.
>> save x -append
Error using save
Unable to write file x: No such file or directory.
>>
It errors if there isn't an existing .mat file on which to append the existing array.
>> save x
>> save x -append
>> delete x.mat
>> x=[];
>> save x
>> x=rand(10,1);
>> save x -append
>> clear x
>> load x
>> whos x
Name Size Bytes Class Attributes
x 10x1 80 double
>>
Closest I could come was to create an empty file first; you could do that as part of an initialization step and then the remaining code could, it appears, be identical even for the first "real" case.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!