Index exceeds matrix dimensions for fprintf

Sinfo = {{'John','Doe'},'ENG141','F13',[89,100,90,70]};
fprintf('Student Name:\t%s,%s\nCourse-Term:\t%s - %s\n\nHighest assignment grade:\t%s\nAverage assignment grade:%s\t',Sinfo{1}(1,2),Sinfo{1}(1,1),Sinfo{2},Sinfo{3},max(Sinfo{4}),mean(Sinfo{4}))
The Sinfo is a given cell array which I must use to create the fprintf, but I keep getting the error Index exceeds matrix dimensions.". I'm still learning so I don't understand fully what is wrong. Thank you!

Answers (2)

It does not have a problem with index exceeding matrix dimension, but it does have a problem with trying to print a cell as a string.
fprintf('Student Name:\t%s,%s\nCourse-Term:\t%s - %s\n\nHighest assignment grade:\t%s\nAverage assignment grade:%s\t',Sinfo{1}{1,2},Sinfo{1}{1,1},Sinfo{2},Sinfo{3},max(Sinfo{4}),mean(Sinfo{4}))

1 Comment

I don't understand what this means. Can you please give a link or explain further?

Sign in to comment.

If you really get the " Index exceeds matrix dimensions." error, you have redefined a Matlab command as a variable:
which max
which mean
Do not use these names as variables, because this shadows the builtin functions.

Asked:

on 12 Jul 2017

Commented:

on 11 Apr 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!