Created
March 1, 2020 19:02
-
-
Save arnobk/1380e7380d5625f09442c7b27bdf886a to your computer and use it in GitHub Desktop.
Matlab Code for sorting array using bubble sort algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
close all | |
clear all | |
clc | |
data1 = [2 5 4 5 4 4 1 3]; | |
data2 = [.02 .13 .14 .63 .53 .11 .22 .26]; | |
for i= 1:length(data1) - 1 | |
for j = 1:length(data1) - 1 | |
if(data1(j)>data1(j+1)) | |
temp1 = data1(j); | |
data1(j) = data1(j+1); | |
data1(j+1) = temp1; | |
temp2 = data2(j); | |
data2(j) = data2(j+1); | |
data2(j+1) = temp2; | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment