I need help with a matrix input and a vector output! please !!

1 visualización (últimos 30 días)
Ibrahim
Ibrahim el 19 de En. de 2015
Comentada: Ibrahim el 20 de En. de 2015
Hello ! I had written all the question here, but for some reasom my computer shut Down.. and i did not save it, so i have attached a Picture of the description instead of writing it down Again. Please see the attached image! : "help matlab.jpg"
I wrote a code as follows:
%(EXAMPLE: a Matrix, lets call it S, like:
| Studentnumber| Name | grade1 | grade2 | grade3 | grade4 |
| S1 | JACK | 2 | 2 | 4 | 7 |
| S2 | RYAN | 10 | 7 | 10 | 7 |
| S3 | PETER| 7 | 7 | 4 | 7 |
| S4 | HARRY| 12 | 10 | 10 | 12 |
| S5 | WILL | 2 | 0 | -3 | 4 |
| S6 | LEIF | 10 | 7 | 4 | 7 |
%For each condition i will use an IF/else function.
If s(:,i) = 1;
finalValue = s(:,i,1);
% for the second condition: ( first the lowest element is removed by MIN
% function and then the average of the rest of the numbers is calculated by MEAN.
elseif s(:,i) > 1
f = min(s(:,i) - s(:,i)
final value = mean(f)
% for the last condition if any of the grades = -3, the final value = -3.
elseif s(:,i)==-3
finalValue = -3.
end
end
(I also thought about using a for loop to run through each row of the matrix, but when i do so the names get "used" to and matlab displays an error. if i for instance use a csv file containing only the numbers then it will Work with a for-loop. But since i need to used csv file with the studentnumber, and names, it won't Work)
The final output should be a vector with length N, containing the final value for each student. Can someone out there please help me out with this ? I will really appreciate it!
Also the values of the grades can only be those of the 7- step - scale: [-3, 0, 2, 4, 7, 10, 12] And the purpose of the script is to run a csv file containing the matrix and then evaluate the answers.
Thanks for your time !
  9 comentarios
Ibrahim
Ibrahim el 20 de En. de 2015
Editada: Ibrahim el 20 de En. de 2015
Hey Again! My code now Works for the first to conditions, but i cannot make it Work for the last one, can someone please have a look at it and help me?
% My code:
[N M] = size(grades);
i = 1:N;
% The logical vector to include the data:
includedData = true(size(grades, 1), 1);
% The three ways to calculate the final grade:
if M == 1
includedData = grades(i,M);
elseif M > 1
includedData = (sum(grades')-min(grades'))/(M-1);
elseif M == -3
includedData = -3;
end
% Display of the Final grade:
gradesFinal = (includedData');
end
Also : couldn't i just remove the "gradesFinal=includedData', and just write gradesFinal instead of includedData under each condition?
Thanks!
Ibrahim
Ibrahim el 20 de En. de 2015
Thanks dpb, i will look at it again. To be honest i don't understand, but i will read it through again :) .. Yes, i have only 10 days experience of matlab from basic "programming". I really appreciate your time and help! Thanks!!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by