使用特定数据构建表

  • 本文关键字:构建 数据 matlab
  • 更新时间 :
  • 英文 :


>我需要一些帮助来完成我的任务:

我有 4 个带有数据的向量:其中 3 个带有日期,第 4 个带有逾期天数,如下所示:

dateAdded      dueDate    date       overdue
Published   
02/11/18       02/11/18   03/11/18    1
03/11/18       04/11/18   11/11/18    7
03/11/18       04/11/18   04/12/18    30
04/11/18       05/11/18   ongoing     overdue up to today

您能否给我一些提示,考虑到当我从一个月过渡到另一个月时,我必须计算两个月的逾期天数,如何创建一个包含一年中每个月逾期天数的表?此外,当发布日期尚未到来时,我必须计算每个月过去的逾期日期。

谢谢

我的解决方案:

number_months = max(((year(dateAdded)-2018))*12 + rem(month(dateAdded),13));
idx = 1;
ii=1;
for k=1:number_months
kpit(k,1) = k;
kpit(k,2) = 0;
kpit(k,3) = 0;
end

for i=1:data_length_Added
%         if month(dateAdded(i)) == month(dueDate(i)) && month(dateAdded(i)) ~= 0
if month(dueDate(i)) == month(datePublished(i)) && month(dateAdded(i)) ~= 0
[~,idx]=ismember(month(dueDate(i)),kpit(:,1),'rows');% finds the position of an element from the array in the array for months
kpit(idx,2) =kpit(idx,2) + overdue(i);
kpit(idx,3) = kpit(idx,3) + 1;
idx = idx + 1;
else if month(datePublished(i)) == month(dueDate(i)) + 1
[~,idx]=ismember(month(dueDate(i)),kpit(:,1),'rows');
[~,idx1]=ismember(month(datePublished(i)),kpit(:,1),'rows');
year1 = year(datePublished(i));
weight = (day(datePublished(i)))/eomday(year1,month(datePublished(i)));
kpit(idx,2) =kpit(idx,2) + overdue(i);
kpit(idx1,2) =kpit(idx1,2) + overdue(i)*weight;
kpit(idx,3) = kpit(idx,3)+ 1;
kpit(idx1,3) = kpit(idx1,3)+ 1;
if (month(datePublished(i)) ~= 0 && month(datePublished(i)) > month(dueDate(i))+1)
%                                if (datePublished > dueDate)% If the correction is done check every month if it is the next one
[~,idx]=ismember(month(datePublished(i)),kpit(:,1),'rows');
year1 = year(datePublished(i));
weight = day(datePublished(i))/eomday(year1,month(datePublished(i))); %Should count all overdue days for full months and weighted overdue dats for not full months
kpit(idx,2) = overdue(i)*weight;
kpit(idx,3) = kpit(idx,3) + 1;
for j=(month(datePublished(i))-1):month(dueDate(i))
[~,idx]=ismember(month(datePublished(j)),kpit(:,1),'rows');
kpit(idx,2) =kpit(idx,2) + overdue(j);
kpit(idx,3) = kpit(idx,3)+ 1;
j = j +1;
end
end
end
end
else if month(dueDate(i)) == 0
[~,idx]=ismember(month(today),kpit(:,1),'rows');
year1 = year(today);
weight = day(today)/eomday(year1,month(today)); %Should count all overdue days for full months and weighted overdue dats for not full months
kpit(idx,2) = overdue(i)*weight;
kpit(idx,3) = kpit(idx,3) + 1;
for j=(month(today)-1):month(dueDate(i))
[~,idx]=ismember(month(today),kpit(:,1),'rows');
kpit(idx,2) =kpit(idx,2) + overdue(j);
kpit(idx,3) = kpit(idx,3)+ 1;
j = j +1;
end
end
end

相关内容

  • 没有找到相关文章

最新更新