MATLAB: ‘num2str’ Error

disperrorMATLABnum2str

Trying to have this result
Details- name:Tara Wilkins, ID:12344567, address:123 Happy Drv
Having errors when using num2str for the ID part, what am I doing wrong?
students(i) = struct();
students(1).ID = 12344567;
students(1).name = 'Tara Wilkins';
students(1).address = '123 Happy Drv';
students(2).ID = 15432123;
students(2).name = 'Fred Bloggs';
students(2).address = '125 Happy Drv';
students(3).ID = 34765765;
students(3).name = 'Jo Tamry';
students(3).address = '321 Happy Drv';
for i = 1:length(students)
disp(['Details- name:' ,students(i).name, 'ID:',students(i).[num2str(ID)], ', address:' ,students(i).address])
end
*Bolded the part that is the issue*

Best Answer

Yes, what you have written makes no sense at all. You want to convert the numeric content of students(i).ID to text, so that's what you should pass to num2str:
... num2str(students(i).ID)
However, instead of building your display string by concatenation and num2str, I would recommend you use sprintf. To me, it makes the whole thing easier to read:
disp(sprintf('Details- name: %s, ID: %d, address: %s', students(i).name, students(i).ID, students(i).address));
Note that I've added some spaces and commas between the different entries that your disp was missing. It's a lot easier with sprintf to see what the final result will look like.
You could also use fprintf directly instead of disp(sprintf(...)):
fprintf('Details- name: %s, ID: %d, address: %s\n', students(i).name, students(i).ID, students(i).address); %added a \n, line return for fprintf