Skip to content

Instantly share code, notes, and snippets.

@arnobk
Created March 1, 2020 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnobk/1380e7380d5625f09442c7b27bdf886a to your computer and use it in GitHub Desktop.
Save arnobk/1380e7380d5625f09442c7b27bdf886a to your computer and use it in GitHub Desktop.
Matlab Code for sorting array using bubble sort algorithm
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