Question

Need help on this Matlab problem, I do not know how to do it

Problem 2. (2D Sorting) The following table contains the scores for the 4 students A,B.C and D for four Homeworks HW1 50 20 8

20 30 15 40 Also obtain, using the sort command, the following matrix which contain the indices of the above matrix prior t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Some time Matlab shows an error, index exceeds, if this type error happens when you run the program then close the Matlab IDE, after that run the fresh Matlab then copy and paste the program on Matlab terminal.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Matlab code with Sample output:

>> % a) Create a matrix with the above data creatematrixdata = [50 45 75 55;20 80 35 40:85 30 15 60;65 95 80 100) creatematri

>> $ Create a matrix with the above data creatematrixdata = [50 45 75 55;20 80 35 40;85 30 15 60;65 95 80 100); $% b) The min

>> $ Create a matrix with the above data creatematrixdata = [50 45 75 55;20 80 35 40;85 30 15 60;65 95 80 100); $% b) The min

>> $% d) Display the minimum score for which HW $$ student C got the minimum score (-, hw]=min(creatematrixdata (3,:)); %% Di

>> $8 e) Calculate the standard deviation of the $$ scores for each homework % % Display the score for each homework fprintf(>> $$ £) Calculate the standard deviation of the 3% scores for each student $% Display the score for each student fprintf (S

>> % g) find the minimum score for each exam without %% using the min() function and create the output %% declare the createm

>> * h) For each exam sort the score in descending order from low to high with contain the indices % of the matrix [BI] - sor

>> $8 i) obtain the following output using Reshape reshape (creatematrixdata, [2,8]) ans - 20 85 65 45 80 30 95 75 155560 35

Simple program screenshot by given order:

% a) Create a matrix with the above data creatematrixdata = [50 45 75 55; 20 80 35 40;85 30 15 60; 65 95 80 100); %% b) The m[-,hw]=min (creatematrixdata (3,:)); 8% Display the student homework number fprintf(Student C got the minimum score for homefor ksd=2:length(creatematrixdata (:,1)); & check out the condition if (minimumscore (msd) > creatematrixdata (ksd, msd)) min

Note: You can use this program individually as like the above-provided screenshot, if you wanna. I'm provide combine code of all the given requirements.

Code to copy:

% a) Create a matrix with the above data

creatematrixdata = [50 45 75 55;20 80 35 40;85 30 15 60;65 95 80 100]

%% b)The minimum score of all four homework

%% using the min function

[minimumScore,studentminimumscore]=min(min(creatematrixdata));

%% Display the minimum score of all four homework.

fprintf('Minimum score of all four homework: %d\n',minimumScore)

%% c) Display that student with the minimum

%% score overall assignment

fprintf('Student with the minimum score: ')

%% Check the condition whose score is

%% minimum

%% when minimum score is in row 1

if studentminimumscore==1

    %% than display the student A

    fprintf('Student A\n')

   

%% otherwise when student minimum score is in row 2

elseif studentminimumscore==2

    %% than display the student B

    fprintf('Student B\n')

   

%% otherwise when student minimum score is in row 3

elseif studentminimumscore==3

    %% than display the student C

    fprintf('Student C\n')

   

%% otherwise when student minimum score is in row 4

elseif studentminimumscore==4

   

    %% than display the student D

    fprintf('Student D\n')

%% end of the ifelse statement

end

%% d) Display the minimum score for which HW

%% student C got the minimum score

[~,hw]=min(creatematrixdata(3,:));

%% Display the student homework number

fprintf('Student C got the minimum score for homework HW%d\n',hw)

%% e) Calculate the standard deviation of the

%% scores for each homework

%% Display the score for each homework

fprintf('Standard deviation of the score for each homework: ')

%% Compute the standard deviation

disp(std(creatematrixdata))

%% Display the mean of the scores for each homework

fprintf('Mean of the score for each homework: ')

%% Compute the mean of the score for each homework

disp(mean(creatematrixdata))

%% f) Calculate the standard deviation of the

%% scores for each student

%% Display the score for each student

fprintf('Standard deviation of the score for each student:\n ')

%% Compute the standard deviation

disp(std(creatematrixdata')')

%% Display the mean of the scores for each student

fprintf('Mean of the score for each student:\n ')

%% Compute the mean of the score for each student

disp(mean(creatematrixdata')')

%% g) find the minimum score for each exam without

%% using the min() function and create the output

% loop to access the create matrix length

for msd=1:length(creatematrixdata (1,:));

    % compute the minimum score

    minimumscore(msd)= creatematrixdata (1,msd);

    % loop to compute the next column data

    for ksd=2:length(creatematrixdata (:,1));

         % check out the condition

         if(minimumscore (msd)> creatematrixdata (ksd,msd))

                minimumscore (msd)= creatematrixdata (ksd,msd);

         end

     end

end

% display the result of minimum score

minimumscore

%% h)For each exam sort the score in descending

% order from low to high with contain the indices

% of the matrix

[B,I] = sort(creatematrixdata,'descend')

%% i) obtain the following output using Reshape

reshape(creatematrixdata,[2,8])

Add a comment
Know the answer?
Add Answer to:
Need help on this Matlab problem, I do not know how to do it Problem 2....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT