1

I have 14 fields inside of a structure and I want to print out like this at the same time with the use of one function. I am not sure on how to loop print all the objects inside the struct.

the code I used to display this is:

student(1);

             Name: 'Brian Leemark Po'
       Attendance: [0 1 1 1 0 0 0 1 0 0]
AttendanceAverage: 0.4000
             Quiz: [100 100 100 100 100]
      QuizAverage: 100
          Project: [77 65 87 59 85]
   ProjectAverage: 74.6000
BenMorel
  • 34,448
  • 50
  • 182
  • 322

2 Answers2

0

This should do the trick:

fNames = fieldnames(student);

for i = 1:length(fNames)
    fprintf('%s: ', fNames{i});
    disp(student.(fNames{i}));
end
DavidS
  • 2,344
  • 1
  • 17
  • 18
-1

Well you can access fields as student(i).Name and print it same for all fields and put this in loop and you can all structure elements.