You should modify the answer likes the following:
result = []; new_row = 1; col_num = 1; row_num = 0;
limit = 7000;
for idx = 1:length(V)
if col_num == 7
new_row = 1
end
if(V(idx) > limit && new_row == 0) % case 1
result(row_num, col_num) = V(idx);
col_num = col_num + 1;
elseif(V(idx) > limit && new_row == 1) %case 2
row_num = row_num + 1; new_row = 0; col_num = 2;
result(row_num, 1) = V(idx);
elseif(V(idx) <= limit) %case 3
new_row = 1;
end
end
if size(result,2) < 6
result(1,6) = 0;
end
Add the follwoing lines to check the col_num
does not exceed from 6
:
if col_num == 7
new_row = 1
end
At the end, check if the column size of the result
is not 6
, modify the result
matrix likes the following:
if size(result,2) < 6
result(1,6) = 0;
end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…