Add lines to a struct
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a struct where one of the columns is the PatientID that appears like this 'P00000001' and I want to add more patients with a diferent PacientID but with the same structer ('P00000001' - a string with P and 8 numbers) how do I do?
2 Kommentare
Stephen23
am 27 Dez. 2021
"structs do not have "columns""
This structure has three columns:
S = struct('A',{1,2,3;4,5,6})
size(S,2)
Antworten (1)
Adam Danz
am 27 Dez. 2021
Bearbeitet: Adam Danz
am 27 Dez. 2021
s = struct();
s.(sprintf('P%08.0f',1)) = 'Baetriz';
s.(sprintf('P%08.0f',2)) = 'Adam';
s.(sprintf('P%08.0f',3)) = 'Matlab'
Or if you're refering to tables,
T = table();
T.(sprintf('P%08.0f',1)) = 'Baetriz';
T.(sprintf('P%08.0f',2)) = 'Adam';
T.(sprintf('P%08.0f',3)) = 'Matlab'
2 Kommentare
Steven Lord
am 27 Dez. 2021
If you're using a table you probably want each patient to be a row of data, with the IDs as the RowNames.
t = table("Baetriz", 'VariableNames', "Name", 'RowNames', "P00000001")
t{sprintf("P%08d", 2), 'Name'} = "Steve"
n = t{'P00000001', 'Name'}
Adam Danz
am 27 Dez. 2021
Or if you want to add row names all at once,
names = ["Baetriz";"Steve";"Adam"]
rownames = compose('P%08d',1:numel(names))
T = table(names, 'RowNames', rownames)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!