473,382 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

a very simple question, pls help a new programmer

I used to write program in Matlab. I have no experience in C++ at all.
But my boss order me to convert a matlab function to C++ function, so
he can use it with his program. For the concept of the program, it
receive a new input and keep some variable in memory to give a output.
Could you please tell me what mistake I have make in the program?

Thanks
#include <stdio.h>
#include <math.h>
class CGripperHysteresis {

private:

public:
CGripperHysteresis( );
void SetThreshold( double threshold);
double CalculateOutput( CGripperHysteresis, double input_data);
};

CGripperHysteresis::CGripperHysteresis( )
{
double m_last_update_side = 0;
double m_last_on_curve_value = 0;
double m_threshold = 0;
double output_data = 0;
double input_data = 0;
}

void CGripperHysteresis::SetThreshold( double threshold)
{
m_threshold = threshold;
}


double CGripperHysteresis::CalculateOutput(CGripperHyster esis, double
input_data)
{
double output_data_temp;

if (m_last_update_side == 0 && m_last_on_curve_value == 0)
{
if (input_data <= threshold){
output_data = 0;
m_last_update_side = 0;
m_last_on_curve_value = 0;}
else if (input_data threshold){
output_data = (input_data-threshold)/(1-threshold) ;
m_last_update_side = 0;
m_last_on_curve_value = output_data;
}
}
else if (m_last_update_side == 0 && m_last_on_curve_value 0 &&
m_last_on_curve_value <1)
{
output_data_temp = (input_data-threshold)/(1-threshold);
if (output_data_temp >= m_last_on_curve_value)
{
output_data = output_data_temp;
m_last_update_side = 0;
m_last_on_curve_value = output_data_temp;
}
else if (output_data_temp < m_last_on_curve_value && input_data >
m_last_on_curve_value*(1-threshold))
{
output_data = m_last_on_curve_value;
m_last_update_side = 0;
m_last_on_curve_value = m_last_on_curve_value;
}
else if (output_data_temp < m_last_on_curve_value && input_data <=
m_last_on_curve_value*(1-threshold))
{
output_data = m_last_on_curve_value;
m_last_update_side = 1;
m_last_on_curve_value = output_data;
}
}
else if (m_last_update_side == 0 && m_last_on_curve_value >= 1)
{
if (input_data >= (1 - threshold))
{
output_data = 1;
m_last_update_side = 0;
m_last_on_curve_value = 1;
}
else if (input_data < (1 - threshold))
{
output_data = (input_data)/(1-threshold) ;
m_last_update_side = 1;
m_last_on_curve_value = output_data;
}
}
else if (m_last_update_side == 1 && m_last_on_curve_value <= 1 &&
m_last_on_curve_value 0)
{
output_data_temp = (input_data)/(1-threshold);
if (output_data_temp <= m_last_on_curve_value)
{
output_data = output_data_temp;
m_last_update_side = 1;
m_last_on_curve_value = output_data_temp;
}
else if (output_data_temp m_last_on_curve_value && input_data <
m_last_on_curve_value*(1-threshold) + threshold)
{
output_data = m_last_on_curve_value;
m_last_update_side = 1;
m_last_on_curve_value = m_last_on_curve_value;
}
else if (output_data_temp m_last_on_curve_value && input_data >=
m_last_on_curve_value*(1-threshold) + threshold)
{
output_data = m_last_on_curve_value;
m_last_update_side = 0;
m_last_on_curve_value = m_last_on_curve_value;
}
}
else if (m_last_update_side == 1 && m_last_on_curve_value == 0)
{
if (input_data < threshold)
{
output_data = m_last_on_curve_value;
m_last_update_side = 0;
m_last_on_curve_value = m_last_on_curve_value;
}
else if (input_data >= threshold)
{
output_data = (input_data-threshold)/(1-threshold) ;
m_last_update_side = 0;
m_last_on_curve_value = output_data;
}
}
return output_data;
}

Aug 9 '06 #1
2 1249

Marco wrote:
I used to write program in Matlab. I have no experience in C++ at all.
But my boss order me to convert a matlab function to C++ function, so
he can use it with his program. For the concept of the program, it
receive a new input and keep some variable in memory to give a output.
Could you please tell me what mistake I have make in the program?

Thanks
#include <stdio.h>
#include <math.h>
class CGripperHysteresis {

private:

public:
CGripperHysteresis( );
void SetThreshold( double threshold);
double CalculateOutput( CGripperHysteresis, double input_data);
};

CGripperHysteresis::CGripperHysteresis( )
{
double m_last_update_side = 0;
double m_last_on_curve_value = 0;
double m_threshold = 0;
double output_data = 0;
double input_data = 0;
}
Here is one mistake. Those members should be declared in the class and
initialized in the constructor. You should also consider using
constructor initialization instead of setting values in the constructor
body.

Aug 9 '06 #2

"Marco" <mo******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>I used to write program in Matlab. I have no experience in C++ at all.
But my boss order me to convert a matlab function to C++ function, so
he can use it with his program. For the concept of the program, it
receive a new input and keep some variable in memory to give a output.
Could you please tell me what mistake I have make in the program?
It might help if you told us what the problem is. Is it failing to compile?
If so, what error messages do you get, and for what lines of code? Is it
compiling, but not running properly? If so, have you tried debugging it?
Does it produce wrong output? Or crash?

You need to tell us exactly what help you want, not just ask us what's wrong
with some random code.

-Howard
Aug 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++...
6
by: Beach Potato | last post by:
Hi: I've searched newsgroups and various archives, including MSDN & MFC sources, but at this point failed to locate an accurate and simple implementation of WndProc function for MSWindows window...
5
by: Rich | last post by:
I have a simple, single threaded program in C++ that runs as Idle priority. The program creates some data which needs dumping to file if the computer is shutdown or logged out. At the moment...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
13
by: aum | last post by:
Hi, I'm a Python programmer, just starting to get into javascript. On reading some of the js guides, and not liking any of the OO usage patterns I saw, I've cooked up something which python...
10
by: pipponino | last post by:
I own a simple Virtual Tour Site. At this time I can't afford to hire a programmer to make it everything that I want so I am trying my best to have it function for the time being as best as I can...
13
by: aaragon | last post by:
Hi everyone, I just wanted to know if there is any difference in performance in declarating the variables in the beginning of a function or within for loops. For example: double test() {...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.