1 % Define the number of students
2 numStudents = 3;
3
4 % Initialize an array of structures
5 students(numStudents) = struct(‘Name’, 0, ‘Age’, 0, ‘Grade’, 0);
6
7 % Loop to input student information
for i = 1:numStudents
fprintf(‘Enter information for student %d:n’, i);
% Get student name`your text`
students(i).Name = input('Enter Name: ', 's');
% Get student age
students(i).Age = input('Enter Age: ');
% Get student grade
students(i).Grade = input('Enter Grade: ', 's');
fprintf('n'); % New line for better readability`your text`
end
% Display the entered information
fprintf('The entered student information is:n');
for i = 1:numStudents
fprintf('Student %d:n', i);
fprintf('Name: %sn', students(i).Name);
fprintf('Age: %dn', students(i).Age);
fprintf('Grade: %sn', students(i).Grade);
fprintf('n'); % New line for better readability
end
my error is in line 5 saying:-
Attempt to call constructor struct with incorrect letter case.
Error in struct (line 5)
students(numStudents) = struct('Name', 0, 'Age', 0, 'Grade', 0);
I am not getting the correct ouput..
New contributor
Mohit Hanumante is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.