Question: Please help me fix this MATLAB Code to sort the vector in ASCENDING order and NOT descending order: (Please write a clear explanation in the

Please help me fix this MATLAB Code to sort the vector in ASCENDING order and NOT descending order:

(Please write a clear explanation in the code of what each line does and what was changed to aid my understanding, thanks)

% MATLAB Script that reads a vector, Sort the vector in Descending order and prints

clc; clear;

% Reading input vector from user ipVec = input("Enter a vector: ");

% Sorting vector in descending order using Bubble Sort Logic % Set size to length of the array passed size = length(ipVec); % Outer loop runs from 1 to size for outer_loop=1:size % Inner loop runs from 1 to size-1 for inner_loop=1:size-1 % Comparing elements if ipVec(inner_loop) < ipVec(inner_loop + 1) % Swapping elements temp = ipVec(inner_loop + 1); ipVec(inner_loop + 1) = ipVec(inner_loop); ipVec(inner_loop) = temp; end %end if statement end %end for inner_loop end %end outer_loop

% Printing vector after sorting fprintf(" After Sorting in Descending Order: "); disp(ipVec);

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!