Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8373713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:44:56+00:00 2026-06-09T14:44:56+00:00

I have this loop which generates a vector Diff. How do I place the

  • 0

I have this loop which generates a vector “Diff”. How do I place the values of Diff in an array that records all the Diff’s generated? The problem is that the length of Diff should be a fixed length (36) which is the width of the table “CleanPrice”. But because col_set varies in length (according to the number of NaNs in the data it is reading), then Diff also varies in length. What I need it to do is assign the answers generated according to their appropriate column number. i.e. row(i) of diff should contain col(i) where all other rows in Diff should be assigned a “0” or “NaN”. Basically I need DiffArray to be a (nTrials x 36) array where each row is the (36 x 1) DiffArray generated. At the moment though, each time the length of col changes, I get the following error:

??? Subscripted assignment dimension mismatch.
Error in ==> NSSmodel
at 41 DiffMatrix(end+1,:)=Diff

This is my code:

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

I looked at num2cell in this post but wasn’t sure how to apply it correctly and started getting errors relating to that instead.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:44:57+00:00Added an answer on June 9, 2026 at 2:44 pm

    Is it correct to say you want to add an ‘incomplete’ row to DiffArray? If you know exactly where each element should go you could maybe do something like this:

    indices = [1:7; 2:8; 3:9; [1 2 3 6 7 8 10]];
    Diff = rand(4, 7);
    DiffArray = zeros(4, 10) * NaN;
    
    for row = 1:4
        DiffArray(row, indices(row, :)) = Diff(row,:);
    end
    

    of course in your case you would be calculating Diff and Index (a row vector) inside the loop and not using preassigned arrays. The above is just to illustrate how to use an indexing vector to position a short row in a matrix.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my code, I have this loop, which brings up various 2-hour time blocks.
I have a loop which basically calls this every few seconds (after the timeout):
I have this class in which I run a for loop 10 times. This
Possible Duplicate: php loop through associative arrays i have this piece of code which
I have this code that makes a string and then echos the loop out
Assume that I have some array of data (a vector to be specific). Can
I have the following loop which generates a little snippet of html: for (var
I have a daily process which generates some zip files out of files that
I have php code which executes a loop, inside which it generates the following:
I have a loop which generates tables according to a database content. In other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.