"Is there a way to return the status of writetable, writematrix, or writecell?"
No. But there are workarounds depending on how you'd like to check the status. xlswrite writes the file within a try/catch block and returns false if the try-part throws an error. You could do the same using,
status = true;
try
writetable(___)
catch ME
status = false;
end
You could check if the newly writen file exists using
writetable(T,filename);
if exist(filename,'file')==2
status = true;
else
status = false;
end
If you are concerned about specific values being written to the file, you could read in the newly written file and compare the read-in values with the values that were written to the file. However, be aware of precision limits; the numer pi for example won't be written to infinite decimals.
writetable(T,filename)
Tcheck = readtable(filename);
if max(T.Var1 - Tcheck.Var1)<1e-06
status = true;
else
status = false;
end
I don't find any of these to be useful, though. What good is it if the file wasn't written correctly? Instead, I would assign a constant value true to the status variable and would use assert() to throw an error if any of these tests failed.
assert(exist(filename,'file')==2, 'File missing.')
Tcheck = readtable(filename);
assert(max(T.Var1 - Tcheck.Var1)<1e-06, 'Values in file do not match original data.')
" the old code uses xlswrite, which is according to MATLAB, outdated, and that makes sense why it's not working"
As far as I know, current releases of Matlab should be backward compatible with xlswrite, although it's still a good idea to update those functions.
Best Answer