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

  • Home
  • SEARCH
  • 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 8942423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:30:44+00:00 2026-06-15T11:30:44+00:00

Any idea why Matlab could behave like this? >> sum([0 0 0]) Subscript indices

  • 0

Any idea why Matlab could behave like this?

>> sum([0 0 0])
Subscript indices must either be real positive integers or logicals.

>> sum([1 1 1])

ans =

     4     4     4

Fighting with this more than 2 hours, still can’t get it.
This is the code I run before this happens.
Before running this code – the function sum() works fine.

price = 100;
vola = 0.2;
r = 0.05;
n_step = 3;
dt = 1/250;
S0 = 100;
T = 1;

s = [1 0 0 0;1 2 0 0;1 2 3 0; 1 2 3 4];
prob = 0.5;
n_path = 2^n_step; % bottle neck for binomial approach
avg_price = zeros(n_path, 2); % first column - probability, second - average price
path_matrix = zeros(n_path, n_step); % all possible paths 1-up, 0-down
for k = 0:n_path-1
    path_matrix(k+1, :) = de2bi(k,'left-msb',n_step);
end

node_matrix = path_matrix;
for k=2:n_step
    node_matrix(:, k) = node_matrix(:, k-1) + node_matrix(:, k);
end
node_matrix = node_matrix + 1;

% go through all possible paths and calculate sum of prices
for k = 1:n_path
    % probability of path
    n_up = sum(path_matrix(k, :));
    avg_price(k, 1) = prob^n_up*(1 - prob)^(n_step - n_up);

    % get sum of prices over all states for this path
    sum = s(1, 1);
    for p = 1:n_step
        sum = sum + s(p+1, node_matrix(k, p));
    end
    avg_price(k, 2) = sum;
end
  • 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-15T11:30:45+00:00Added an answer on June 15, 2026 at 11:30 am

    you’ve overridden the function sum and now it is considered a local variable

     sum = s(1, 1);
    

    thus you are hiding sum as function.

    Change the variable name and do

     clear sum
    

    .

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

Sidebar

Related Questions

Anyone have any idea how I can implement this? I'd like to have a
Any idea why this code: extern C __declspec(dllexport) void Transform(double x[], double y[], int
Any idea about ORA-1555: snapshot too old: rollback segment number I am getting this
Any idea why this wont print the errors? // Validate the email if (preg_match($regex,
Have you any idea about implementing 2D object recognition with MATLAB? Which characteristics of
Any idea how make a layout like google plus or facebook. You can see
Any idea to Implementing this? Is this best way to do? boolean contains=string.split(regex,2).length==2; Thanks
Any idea why this works: [[[[[self tabBarController] tabBar] items] objectAtIndex:2] setBadgeValue:@Hello]; But this doesn't?
Any idea why I am getting this exception? Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
Anyone have any idea how knnclassify is implemented in Matlab? I was wondering if

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.