我试着从下面的代码中获取与范围对应的组数,并定义范围变量星星_row,end_row,我总共有8950行数据。但是我发现了一个bug,如果星星_row不从1开始,代码就会出错。我找不到问题。
plot(time_a(star_row:end_row),acceleration(star_row:end_row,2),'b','LineWidth',1.5);
这是我的代码
%D1
close all;
acceleration=gpu_load(1:end,:);
N = size(acceleration,1);
star_row = 3762 ;
end_row = N ;
test = acceleration(star_row:end_row,2).^2;
% non_zero number
non_zero = acceleration(acceleration(star_row:end_row,2) ~= 0, 2);
[dec_max, dec_max_idx] = max((acceleration(star_row:end_row,2).^2).^0.5);
[dec_min, dec_min_idx] = min((non_zero.^2).^0.5);
% GPU average
dec_avg = mean(non_zero);
time_a = (acceleration(star_row:end_row,1)-acceleration(1,1))/10^9;
time_satr = 1;
time_end = size(time_a,1);
figure
hold on
plot(time_a(star_row:end_row),acceleration(star_row:end_row,2), 'b','LineWidth',1.5);
plot(time_a(dec_max_idx),acceleration(dec_max_idx,2), '^r','MarkerSize',10);
plot(time_a(dec_min_idx),acceleration(dec_min_idx,2), '^r','MarkerSize',10);
h1 = legend('GPU usage',sprintf('Maximum GPU Usage = %0.3f', dec_max),sprintf('Minimum GPU Usage = %0.3f', dec_min), sprintf('Mean GPU Usage = %0.3f', dec_avg));
set(h1,'FontSize',15);
set(gca,'FontSize',15);
xlabel('Time (Sec)','FontSize',15,'FontWeight','bold');
ylabel('GPU usage','FontSize',15,'FontWeight','bold');
axis([star_row end_row 0 150]);
hold off
grid on
错误消息:
Index exceeds the number of array elements. Index must exceed 5189.
Error in draw (line 23)
plot(time_a(star_row:end_row),acceleration(star_row:end_row,2), 'b','LineWidth',1.5);
非常感谢你的任何建议
我试着改变瞄准镜来确认他的错误来源
1条答案
按热度按时间von4xj4u1#
我假设,数组time_a的大小是N-start_row,并且需要替换
类似的东西
因为time_a数组小于加速度