It appears the last column of the output from the problem statement should be 3.5; 0.0; 2.0 instead of 3.5; 0.0; 3.0, but the first test suite does have it correct.
yes true, thank you
Thank you! Modified the problem statement.
Why doesn't it work?
function X = rescale_scores(X)
X = [X(1:end,1:end-1) (X(1:end,end).-60)./4]
end
n = size(X,1);
for c = 1:n
X(c,end) = (X(c,end)-60)/10;
end
A little bit of math work will make your program much simpler. Grade 60-100 for GPA 0 - 4, this is a straight line! The equation for this straight line is GPA = 0.1*(grade-60). Don't forget to take care of negative GPAs.
function X = rescale_scores(X)
Y = X(:,end)
[m,n] = size(X)
a = 1
B = []
for p = 1:m
if 60 <= Y(a) < 70
c = (Y(a)-60)./10
B = [B;c]
a = a+1
elseif 70 <= Y(a) < 80
c = ((Y(a)-70)./10).*2
B = [B;c]
a = a+1
elseif 80 <= Y(a) < 90
c = ((Y(a)-80)./10).*3
B = [B;c]
a = a+1
elseif 90 <= Y(a) < 100
c = ((Y(a)-90)./10).*4
B = [B;c]
a = a+1
end
end
X = [X(:,1:end-1),B]
end
X(:,end)=mean(rescale(X(:,end-1),-6,4,'InputMin',0,'InputMax',100),2);
Don't forget the negative numbers.
Score GPA
90 - 100 3 - 4
80 - 90 2 - 3
70 - 80 1 - 2
60 - 70 0 - 1
50 - 60 -1 - 0
40 - 50 -2 - -1
30 - 40 -3 - -2
20 - 30 -4 - -3
10 - 20 -5 - -4
0 - 10 -6 - -5
Easy!
X(:,end)=rescale(X(:,end),0,4,'InputMin',60,'InputMax',100);
Although my method is stupid and complicated,it still works.
function X = rescale_scores(X)
rown=length(X(1,:));
cn=length(X(:,1));
for c=1:cn
if X(c,rown)>=90
A=rescale([90,X(c,rown),100],3,4);
X(c,rown)=A(2);
elseif X(c,rown)>=80
A=rescale([80,X(c,rown),90],2,3);
X(c,rown)=A(2);
elseif X(c,rown)>=70
A=rescale([70,X(c,rown),80],1,2);
X(c,rown)=A(2);
else
A=rescale([60,X(c,rown),70],0,1);
X(c,rown)=A(2);
end
end
end
it is ridiculous but still, it works. feel free to improve it.
function X = rescale_scores(X)
t=zeros(size(X,1)+2,size(X,2));
adjustment=[60;100];
t(1:end-2,1:end)=X;
t(end-1:end,end)=adjustment;
initial_finals=rescale(t(:,end),0,4);
X(:,end)=initial_finals(1:end-2,:);
end
A= 60:0.1:100;
A_reescale= rescale(A,0,4);
for c=1:size(X,1);
for d=1:size(A,2);
if X(c,(size(X,2)))==A(d);
X(c,(size(X,2)))=A_reescale(d);
end
end
end
Please, what is wrong with the following answer
X = (X-60)/10;
thank u
This would operate on the entire matrix X. However we want the GPA to appear only in the last column of X. So try by declaring another variable which would calculate the GPA and then replace the last column of X with this column vector.
We have to modify only last column of matrix X not an entire matrix so find GPA for that column only.
2003 Solvers
1813 Solvers
How to find the position of an element in a vector without using the find function
2482 Solvers
Create a two dimensional zero matrix
361 Solvers
Find out sum and carry of Binary adder
397 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!