Problem 44960 Rescale scores

5 vues (au cours des 30 derniers jours)
Tavish Pattanayak
Tavish Pattanayak le 7 Mai 2020
Commenté : Minu Muhsina le 2 Déc 2022
The following code works fine with the first set of input tested however shows error for the second set. I am doing this on Cody. Could anyone tell me what's wrong?
function X = rescale_scores(X)
A= 60:100;
B= rescale(A,0,4);
for c=1:40;
for d=1:size(X,1);
if X(d,length(X))==A(c);
X(d,length(X))=B(c);
end
end
end
X
end

Réponse acceptée

Ameer Hamza
Ameer Hamza le 7 Mai 2020
This can be solved using a one-liner
function X = rescale_scores(X)
X(:,end) = interp1([60 100], [0 4], X(:,end));
end
  4 commentaires
Tavish Pattanayak
Tavish Pattanayak le 8 Mai 2020
Thank you!
Minu Muhsina
Minu Muhsina le 2 Déc 2022
I used the following code. But it doesn't work on Test 1. It shows Assertion failed.
Could anyone help me with this.
function X = rescale_scores(X)
X(:,end)=(X(:,end)-60)/10;
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by