MATLAB: Merge two tables in Matlab

errorguiMATLABmerge tablesstructurestable

Hello,
So, I have this GUI program where I have a table loaded from a .txt file on this code:
global T;
opts = detectImportOptions('pacientes.txt');
opts = setvartype(opts,{'PatientN', 'Name', 'Sex', 'Birth', 'Country', 'Status', 'Address', 'Diagnostics', 'Phone', 'ExamN', 'ExamDate', 'Type', 'BrainMassPercentage'}, ,'string');
T = readtable('pacientes.txt', opts);
Later, when the user clicks a button, I want to add a new row to table T where I get the variables from a GUI text box. So I do the following:
global T;
name = get(handles.name2, 'String');
contents = get(handles.gender2, 'String');
gender = contents{get(handles.gender2, 'Value')};
patientN = get(handles.number2, 'String');
birth = get(handles.birth2, 'String');
country = get(handles.country2, 'String');
contents = get(handles.status2, 'String');
status = contents{get(handles.status2, 'Value')};
address = get(handles.address2, 'String');
diagnostics = get(handles.diagnostics2, 'String');
phone = get(handles.phone2, 'String');
newPatient(1,1).PatientN = cellstr(patientN);
newPatient(1,1).Name = name;
newPatient(1,1).Gender = gender;
newPatient(1,1).Birth = birth;
newPatient(1,1).Country = country;
newPatient(1,1).Status = status;
newPatient(1,1).Address = address;
newPatient(1,1).Diagnostics = diagnostics;
newPatient(1,1).Phone = phone;
newPatient(1,1).ExamN = '';
newPatient(1,1).ExameDate = '';
newPatient(1,1).Type = '';
newPatient(1,1).BrainMassPercentage = '';
S = struct2table(newPatient, 'AsArray', true);
T = [T;S];
However, when the program reaches T = [T;S] it throws the error: "All tables in the bracketed expression must have the same variable names." and I don't understand why. Variable names are exactly the same both in T, S and the .txt file (and in the same order).
Can anyone please help? Thank you!

Best Answer

T has a variable Sex but newPatient has a variable Gender