在matlab中绘制同一趋势线上的两个函数

时间:2013-04-20 00:14:20

标签: matlab

这是我的原始代码:

function a = graph_times()
merge_times = [];
for i = 100:100:1000
    curr = sort_timer(i);
    merge_times = [merge_times, curr(1)];
end
plot(100:100:1000, merge_times);

a = 1;
end

我想修改此代码,以便在同一图表上绘制insertion_sortmerge_sort的趋势线。 以下是merge_sortinsertion_sort

的功能
function c = insertion_sort(list1)
inserted = [];
for i = 1:size(list1,2)
inserted = insert_in_order(inserted,list1(1,i))
c = inserted
end
steps2=0;

function b = merge_sort(nums)
    if size(nums,2) == 1
        b = nums;
        return;
    end

1 个答案:

答案 0 :(得分:0)

您可以为MATLAB的plot函数提供几组坐标。您可以绘制两种排序算法的时间,如下所示:

plot(100:100:1000, merge_times, 100:100:1000, insertion_times);