How do I save each response in an excel file every time I click the submit button?
It currently only saves the recent response and not the previous response as well.
function SubmitButtonPushed(app, event)
data = {firstName, lastName, dob, email, nationality, sex, mobileNumber, type};
passengerData = cell2table(data, ‘VariableNames’, {‘First Name’, ‘Last Name’, ‘Date of Birth’, ‘Email’, ‘Nationality’, ‘Sex’, ‘Mobile Number’, ‘Type’});
disp(‘New Passenger Data: ‘)
disp(passengerData)
filename = ‘passengerDetails.xlsx’;
if isfile(filename)
existingData = readtable(filename);
combinedData = [existingData; passengerData];
else
combinedData = passengerData;
end
writetable(combinedData,filename, ‘WriteMode’,’append’);
disp(‘Combined Data: ‘)
disp(combinedData)
new_line = randn(1,9);
sheetName = sprintf(‘Submission_%d’, submissionCount);
writematrix(new_line, filename, ‘Sheet’, sheetName, ‘WriteMode’, ‘overwrite’);
submissionCount = submissionCount + 1;
msgbox(‘Successfully submitted’,’Success’);
delete(app);It currently only saves the recent response and not the previous response as well.
function SubmitButtonPushed(app, event)
data = {firstName, lastName, dob, email, nationality, sex, mobileNumber, type};
passengerData = cell2table(data, ‘VariableNames’, {‘First Name’, ‘Last Name’, ‘Date of Birth’, ‘Email’, ‘Nationality’, ‘Sex’, ‘Mobile Number’, ‘Type’});
disp(‘New Passenger Data: ‘)
disp(passengerData)
filename = ‘passengerDetails.xlsx’;
if isfile(filename)
existingData = readtable(filename);
combinedData = [existingData; passengerData];
else
combinedData = passengerData;
end
writetable(combinedData,filename, ‘WriteMode’,’append’);
disp(‘Combined Data: ‘)
disp(combinedData)
new_line = randn(1,9);
sheetName = sprintf(‘Submission_%d’, submissionCount);
writematrix(new_line, filename, ‘Sheet’, sheetName, ‘WriteMode’, ‘overwrite’);
submissionCount = submissionCount + 1;
msgbox(‘Successfully submitted’,’Success’);
delete(app); It currently only saves the recent response and not the previous response as well.
function SubmitButtonPushed(app, event)
data = {firstName, lastName, dob, email, nationality, sex, mobileNumber, type};
passengerData = cell2table(data, ‘VariableNames’, {‘First Name’, ‘Last Name’, ‘Date of Birth’, ‘Email’, ‘Nationality’, ‘Sex’, ‘Mobile Number’, ‘Type’});
disp(‘New Passenger Data: ‘)
disp(passengerData)
filename = ‘passengerDetails.xlsx’;
if isfile(filename)
existingData = readtable(filename);
combinedData = [existingData; passengerData];
else
combinedData = passengerData;
end
writetable(combinedData,filename, ‘WriteMode’,’append’);
disp(‘Combined Data: ‘)
disp(combinedData)
new_line = randn(1,9);
sheetName = sprintf(‘Submission_%d’, submissionCount);
writematrix(new_line, filename, ‘Sheet’, sheetName, ‘WriteMode’, ‘overwrite’);
submissionCount = submissionCount + 1;
msgbox(‘Successfully submitted’,’Success’);
delete(app); matlab, excel, table MATLAB Answers — New Questions