Question: I created the follwing function: %First for the vector we need to find the largest element the below is the %statement to sort the vector.

 I created the follwing function: %First for the vector we need

I created the follwing function:

%First for the vector we need to find the largest element the below is the %statement to sort the vector.

A=[1 2 5 0 5];

%sorting the vector.

[C,Index] = sort(A,'descend');

%taking the max value.

t = A(Index(1));

%finding the elements which are equal to max value.

idx = find(A==max(A),1,'first');

%using empty vector to deletes the largest elements.

A(idx) = [];

%printing the vector.

g = sprintf(' %d ',A);

fprintf(' Answer: %s ',g);

but the output I'm getting is 1 2 0 5 , it only removes one of the 5's when its supposed to remove both. How can I fix this ?

5.6 Write some statements on the command line to remove the largest element(s) from a vector. Try it out on x [1 2 5 0 5]The idea is to end up with [1 2 0] in x. Use find and the empty vector

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!