outputTable=table(VarNameStr,Screen_Grasp_Average,Grasp_Release_Average,difference);
writetable(outputTable,D:\LocationName\DataLocation\Spreadsheet.xlsx);
D:\LocationName\DataLocation\Spreadsheet.xlsx is invalid syntax -- it isn't quoted to be a string and it isn't valid syntax to catenate variables (if the pieces of it other than punctuation) were actually variables. writetable expects the second argument to be an acceptable filename as either a char() vector or a string...you gave it something unrecognizable.
drive='D:';
folder='LocationName\DataLocation';
file='Spreadsheet.xlsx';
writetable(outputTable,fullfile(drive,folder,file));
will solve your filename problem when you properly define the various pieces for your application.
That will NOT solve the problem of appending to the Excel spreadsheet, however; you'll have to use the optional 'Range' argument to set the starting corner of the sheet to write to. BUT you'll have to figure out what the next available row is because there is no 'append' flag for Excel files as there is for sequential text files. This means keeping track of how many records have been written to date and compute the proper range expression based on that.
Depending on how this is going to be used, it may be better to either create the full table first before writing it or reading in the existing data and appending the writing (a lot of overhead) or to just write a sequential text file and then when done read that file and convert it to spreadsheet if think simply must have a spreadsheet.
Best Answer