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 4007264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:36:43+00:00 2026-05-20T08:36:43+00:00

So, we are trying to execute the following code. The two if statements are

  • 0

So, we are trying to execute the following code. The two if statements are executing, however, the inside if statements are failing to execute (we verified this by not suppressing the output). Is there a reason why? Or are we just not able to reach this state?

Specifications

The input is as follows: v is a vector of int values and c is a integer. c must be less than or equal to one of the values within v

The problem that we are trying to solve with this algorithm is as follows:

Given a cash register, how does one make change such that the fewest coins
possible are returned to the customer?

Ex: Input: v = [1, 10, 25, 50], c = 40. Output O = [5, 1, 1, 0]

We are just looking for not a better solution but more of a reason why that portion of the code is not executing.

function O = changeGreedy(v,c)
  O = zeros(size(v,1), size(v,2));
  for v_item = 1:size(v,2)
         %locate largest term
         l_v_item = 1
         for temp = 2:size(v,2)
            if v(l_v_item) < v(temp)
                l_v_item = temp
            end    
         end    

    %"Items inside if statement are not executing"
    if (c > v(l_v_item))
        v(l_v_item) = -1 %"Not executing"
    else
        O(l_v_item) = idivide(c, v(l_v_item)) %"Not executing"
        c = mod(c, v(l_v_item)) %"Not executing"
    end      
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-05-20T08:36:44+00:00Added an answer on May 20, 2026 at 8:36 am

    If c or v are not integers, i.e. class(c) evaluates to double, then I get the following error message

    ??? Error using ==> idivide>idivide_check at 66
    At least one argument must belong to an integer class.
    
    Error in ==> idivide at 42
    idivide_check(a,b);
    

    and the program stops executing. Thus, the inside of the second statement never executes. In contrast, if, say, c is an integer, for example of class uint8, everything executes just fine.

    Also: what are you actually trying to achieve with this code?

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

Sidebar

Related Questions

I'm trying the following code to execute a search and it's not working. On
I am trying to execute the following code. The code tries to parallely download
I m trying to execute some code when image is not loaded. I m
I have been trying to execute the following UNIX shell script which is not
I am trying to execute this SQL query prior to restoring a .BAK file
I am trying to execute this SQL command: SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) FROM page,
I hit this error while my web application was trying to execute a SELECT
I'm trying to execute the following query but I receive a runtime error stating
I am trying to execute a .bat file remotely and implementing following lines of
I'm trying to take two lines of code from an elseif statement and create

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.