Index exceeds matrix dimensions for fprintf
Show older comments
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)
Walter Roberson
on 12 Jul 2017
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
Julia E Kelso
on 11 Apr 2018
I don't understand what this means. Can you please give a link or explain further?
Jan
on 13 Jul 2017
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.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!