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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:57:49+00:00 2026-06-02T23:57:49+00:00

I am trying to find the minimum and maximum values for the continuous while

  • 0

I am trying to find the minimum and maximum values for the continuous while loop given below, but somehow I am unable to get the logic right. Kindly let me know where I am going wrong.

while (true)
   {
         Function(&RawX, &RawY, &RawZ);// Keeps generating new RawX,Y and Z values

         if(MaxRawX < RawX)
            MaxRawX = RawX;
         if(MinRawX > RawX)
            MinRawX = RawX;

         Output("MaxRawX:%0.2f",MaxRawX);
   }

The problem that I am facing with the above algorithm is that the values of RawX, RawY and RawZ are continuously changing. For eg: at one point, I have values ranging from -46 to -35. I want my program to display MinRawX as -46 and MaxRawX as -35. At some other point, I might have values in between 201 to 215, where I want it to display MaxRawX as 215 and MinRawX as 201. Its basically some sensor angle data I receive from my hardware. I am sure I am doing something wrong here considering this being very basic but can’t figure it out. Any suggestions?

  • 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-02T23:57:50+00:00Added an answer on June 2, 2026 at 11:57 pm

    If I understand correctly, you want to have the minimum and maximum for a given time frame. The solution you use keep the minimum and maximum since the beginning of the program.

    Depending on your needs, you have several solutions: for instance, you can simply reset the min and max from time to time, like @dirkgently suggested. If you want a moving range, so that at any point in time you have the min and max of the n last measurements, then you will have to use a more complex solution. The only one I can think of is keeping the measurements in a FIFO container:

    std::deque<int> lastRawXs;
    const int frameSize = 100; // only keep the last 100 measures    
    
    while (true)
    {
        // Keeps generating new RawX,Y and Z values
        Function(&RawX, &RawY, &RawZ);// 
    
        if (lastRawXs.size() >= frameSize)
        {
            lastRawXs.pop_front();
        }
        lastRawXs.push_back(RawX);
    
        typedef std::deque<int>::const_iterator iterator;
        std::pair<iterator, iterator> minMaxRawX =
            boost::minmax_element(lastRawXs.begin(), lastRawXs.end());
    
        Output("MinRawX:%0.2f", *minMaxRawX.first);
        Output("MaxRawX:%0.2f", *minMaxRawX.second);
    }
    

    Edit: Here is an alternative (better) solution using a circular buffer:

    const int frameSize = 100;
    std::circular_buffer<int> lastRawXs(frameSize);
    
    while (true)
    {
        Function(&RawX, &RawY, &RawZ); // keeps generating new RawX,Y and Z values
    
        lastRawXs.push_back(RawX); // overwrites old measures if buffer is full
    
        typedef std::circular_buffer<int>::const_iterator iterator;
        std::pair<iterator, iterator> minMaxRawX =
            boost::minmax_element(lastRawXs.begin(), lastRawXs.end());
    
        Output("MinRawX:%0.2f", *minMaxRawX.first);
        Output("MaxRawX:%0.2f", *minMaxRawX.second);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program that would find the minimum spanning tree. But
hey guys, this is very confusing... i am trying to find the minimum of
I am trying to find the shortest and longest word in a given string.
I'm trying to find minimum of an array. The array contain Nodes - a
I'm trying to find the minimum number in a array using Thrust and CUDA.
I am trying to find the minimum value of a list (as a learning
I'm trying to use std::min_element and std::max_element to return the minimum and maximum elements
I'm trying to use boost's prim's algorithm to find the minimum spanning tree using
I am trying to find the index position of the minimum element in a
I'm trying to find the minimum spanned tree using Mathematica and I want to

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.