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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:49:28+00:00 2026-06-11T02:49:28+00:00

what would be the c++ equivalent to this matlab code? I started it off

  • 0

what would be the c++ equivalent to this matlab code? I started it off but i’m not sure what value B would be, i think A is correct.

MATLAB

array = (-1:.001:1)';

    A = max(find(array < 1.0e-2));
    B = min(find(array > 1 - 1.0e-2));

C++ attempt

for(i = 0; i < array.size; i++){
    if(array[i] < 1.0e-2){ 
    k++
    A = k;
   }
    if(array[i] > (1- 1.0e-2)){
    //not sure what to do here
    B = ?;
   }
}
  • 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-11T02:49:30+00:00Added an answer on June 11, 2026 at 2:49 am

    For the second bit, I would do this instead inside the same loop:

    if(array[array.size-i-1] > (1 - 1.0e-2)) B = array.size - i;
    

    and initialize B to array.size before the loop.

    Essentially, you are finding the element with the lowest index in the array which is also larger than 1 - 1.0e-2. If you start at the element with the highest index and then traverse the entire array and update each time you satisfy the criteria, you will end up with what you need. A similar logic applies for the first part, but you will need to set A = i+1 instead of incrementing k because there is no guarantee the array is sorted.

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

Sidebar

Related Questions

What would be the PHP equivalent to this code, I have tried curl but
I would like to do the equivalent off this (ruby code) in python for
What would be the equivalent of this code in Objective-C? array2[i]=array[i].split(!);
What would be the jQuery equivalent to this Prototype code? If you don't think
What would be jQuery equivalent of this sf hover suckerfish code? <script> sfHover =
What would be the VB.NET equivalent of this code.. public virtual ICollection<Comment> Comments {
I'm looking for the equivalent of what in js would be 'this is a
What would be C# equivalent? private array<__int32>^ func() { }
What would be the PHP equivalent of this Perl regex? if (/^([a-z0-9-]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ and $1
What's the closest GCC equivalent to this MSVC preprocessor code? #pragma warning( push )

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.