我有这个循环,它生成一个向量“Diff”。如何将 Diff 的值放在记录所有 Diff 生成的数组中?问题是 Diff 的长度应该是固定长度(36),即“CleanPrice”表的宽度。但是因为 col_set 的长度不同(根据它正在读取的数据中 NaN 的数量),所以 Diff 的长度也不同。我需要它做的是根据相应的列号分配生成的答案。即 diff 的 row(i) 应该包含 col(i),其中 Diff 中的所有其他行都应该分配一个“0”或“NaN”。基本上我需要DiffArray是一个 (nTrials x 36) 数组,其中每一行都是生成的 (36 x 1) DiffArray。但此刻,每次 col 的长度变化时,
???下标分配尺寸不匹配。==> NSSmodel 在 41 DiffMatrix(end+1,:)=Diff 处出错
这是我的代码:
DiffArray=[];
StartRow=2935;
EndRow=2940;
nTrials=EndRow-StartRow;
for row=StartRow:EndRow;
col_set=find(~isnan(gcm3.data.CleanPrice(row,1:end)));
col=col_set(:,2:end);
CleanPrices=transpose(gcm3.data.CleanPrice(row,col));
Maturity=gcm3.data.CouponandMaturity(col-1,2);
SettleDate=gcm3.data.CouponandMaturity(row,3);
Settle = repmat(SettleDate,[length(Maturity) 1]);
CleanPrices =transpose(gcm3.data.CleanPrice(row,col));
CouponRate = gcm3.data.CouponandMaturity(col-1,1);
Instruments = [Settle Maturity CleanPrices CouponRate];
PlottingPoints = gcm3.data.CouponandMaturity(1,2):gcm3.data.CouponandMaturity(36,2);
Yield = bndyield(CleanPrices,CouponRate,Settle,Maturity);
SvenssonModel = IRFunctionCurve.fitSvensson('Zero',SettleDate,Instruments)
ParYield=SvenssonModel.getParYields(Maturity);
[PriceActual, AccruedIntActual] = bndprice(Yield, CouponRate, Settle, Maturity);
[PriceNSS, AccruedIntNSS] = bndprice(ParYield, CouponRate, Settle, Maturity);
Diff=PriceActual-PriceNSS
DiffArray(end+1,:)=Diff
end
我在这篇文章中查看了num2cell ,但不确定如何正确应用它并开始收到与此相关的错误。