
function segments (row, col, stat, sortcol)

	if ~def(row)
		col = "wave";
	end

	if ~def(stat)
		stat = "rowpct";
	end

	[t1, k, r1, c1] = bigtab(row, col, stat, "", [], [], "noprint");
	r1 = r1(1:size(r1, 1), 2);
	c1(1,:) = [];

	for j = size(t1, 2) : 1 : -1
		if strcmp(c1(1, j), "88888888.00") == 0
			t1(:, j) = [];
			c1(:, j) = [];
		end
	end

	if def(sortcol)
		d = size(t1, 1);
		sortcol = str2num(sortcol);
		red = [];

		%if (sortcol > 1)
			for j = 1 : size(t1, 1)
				manje = 0;
				for i = 1 : size(t1, 1)
					if t1(i, sortcol-1) > t1(j, sortcol-1)
						manje = manje + 1;
					end
				end
				red = [red; manje];
			end
		%end

		ttt = [];
		rrr = [];
		for j = 0 : size(t1, 1)-1
			for i = 1 : size (t1, 1)
				if red(i, 1) == j
					ttt = [ttt; t1(i, :)];
					rrr = [rrr; r1(i, :)];
				end
			end
		end

		red = [];
		for j = 1 : size(ttt, 1)
			manje = 0;
			for i = 1 : size(ttt, 1)
				if ttt(i, sortcol) > ttt(j, sortcol)
					manje = manje + 1;
				end
			end
			red = [red; manje];
		end

		t1 = [];
		r1 = [];
		for j = 0 : size(ttt, 1)-1
			for i = 1 : size (ttt, 1)
				if red(i, 1) == j
					t1 = [t1; ttt(i, :)];
					r1 = [r1; rrr(i, :)];
				end
			end
		end

	end

	print (t1, r1, c1);
end



