I created the follwing function: %First for the vector we need to find the large
ID: 3589629 • Letter: I
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.
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 ?
Explanation / Answer
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));
%using empty vector to deletes the largest elements.
A(idx) = [];
%printing the vector.
g = sprintf(' %d ',A);
fprintf(' Answer: %s ',g);
% basically you were searching only for first element rather than searching for all elements
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.