gpa calculator with matrix

I want to make n by 2 matrix and put the grades for first column and second one fore the units (credits) of the grades and then ask to take the numbers from the user and then clculate the gpa
I tried such an script :
and I don't know what to do any more
I will be so thankful if someone help me
% matrix as a gpa calculator
n = input ('"n" value =') , % n is the number of lessons and grades ???????

Answers (1)

Why not just input the matrix?
m=input('matrix of grades and units, for example [3.5,4;2.7,2;4.0,3;3.3,2]');
gpa=sum(prod(m,2))/sum(m(:,2));

4 Comments

Milad Houshmand
Milad Houshmand on 18 Mar 2021
Edited: Milad Houshmand on 18 Mar 2021
Why does this error come out? :
Index in position 2 exceeds array bounds.
Error in matgpa (line 2)
gpa=sum(prod(m,2))/sum(m(:,2));
and to reply your question I want myself give the matlab all the grades with their credits?
It will be more general
You have to enter the matrix correctly. If you copy and past the example, you should not get an error.
m=[3.5,4;2.7,2;4.0,3;3.3,2];
m =
3.5000 4.0000
2.7000 2.0000
4.0000 3.0000
3.3000 2.0000
you are completely right, but as I said If it is possible lets make it general to ask the users to put the grades for firs column and as the units for the srcond column then operate for gpa . It will be much better and more useful.
.
Ok, make two inputs

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 18 Mar 2021

Commented:

on 18 Mar 2021

Community Treasure Hunt

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

Start Hunting!