可以使用Matlab中的plot函数来绘制图像。具体操作如下:

  1. 定义变量Q和T,用于存储横坐标和纵坐标数据:

Q=[5 10 15 20 25]; T=zeros(2,length(Q));

  1. 在循环中计算T0和T1,并将较大者存入T中:

for s=1:5 nums=randi([10000 50000],1,Q(s)); sorted_nums=sort(nums); for i=1:Q(s) T0=0; T1=0; for m=1:i c(m)=1000sorted_nums(m); T0=T0+c(m)/f0; end for n=i+1:Q(s) c(n)=1000sorted_nums(n); d(n)=sorted_nums(n); T1=T1+d(n)/C+c(n)/f1; end if T0>=T1 k=i; break; end end T(1,s)=T0; T(2,s)=max(T0,T1); end

  1. 使用plot函数绘制图像:

figure; plot(Q,T(1,:),'-o',Q,T(2,:),'-x'); xlabel('任务数'); ylabel('时间(秒)'); legend('T0','max(T0,T1)'); grid on;

其中,'-o'和'-x'表示不同的线型和标记,legend函数用于添加图例,grid on表示添加网格线。最终的图像如下所示:

注:由于程序中存在一些未定义的变量,因此这里只是提供一个绘图思路,具体实现需要根据实际情况进行修改

用Matlabf0=1000000000;f1=5000000000;C=2000000;z=0;Q=5 10 15 20 25;任务数作为自变量确定随机数的生成个数for s=15nums=randi10000 500001Qs;随机数的生成任务输入大小dnsorted_nums=sortnums;从小到大排序 for i=1Qs T0=0; T1=0; for m=1i

原文地址: https://www.cveoy.top/t/topic/fdO1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录