Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

converting NI data types to C

I am writing a program and I am using the following code from the dual sine waves:

// Graph the dual sine graph on both graphs
// Declare variables
CNiReal64Vector xData(41);
CNiReal64Vector yData(41);
CNiReal64Matrix zData(41,41);

// Use a for loop to go through each array point
// and store in a number that results from the equation
for (int i = 0; i < 41; i++)
{
xData[i] = (i - 20.0)/20.0 * PI;
yData[i] = (i - 20.0)/20.0 * PI;
}

// Use two for loops to go through each matrix point of zData
// and store in the results from an equation
for (i = 0; i < 41; i++)
{
for (int j = 0; j < 41; j++)
{
zData(j,i) = sin(xData[i])*cos(yData[j]);
}
}

// Plot the data
m_cSurfaceGraph.Plot3DSurface(xData, yData, zData);



I want to convert the data types into C++ arrays. In other words, I want to use C++ arrays instead of National Instruments array. How shall I do that?
0 Kudos
Message 1 of 2
(3,096 Views)
You can use native C++ data types as much as you like, but ultimately you will have to create Measurement Studio C++ vector/matrix types to display the data in the graph. The vector/matrix types provide constructors that make this very easy. For example, here's a modified version of the example that I posted before that uses C++ double arrays to create the data and converts the arrays to vector/matrix types at the last minute to plot the data:

m_graph3D.ViewMode = CNiGraph3D::ViewXYPlane;
m_graph3D.ViewDistance = 0.7;

CNiPlot3D plot = m_graph3D.Plots.Item(1);
plot.Style = CNiPlot3D::Surface;
plot.ColorMapAutoScale = false;
plot.ColorMapInterpolate = true;
plot.ColorMapLog = false;
plot.ColorMapStyle = CNiPlot3D::Co
lorSpectrum;

// Create dual sine surface data with native C++ double types.
const int SIZE = 41;
double xData[SIZE], yData[SIZE], zData[SIZE][SIZE];
int i, j;

for (i = 0; i < SIZE; ++i)
xData[i] = yData[i] = ((i - 20.0) / 20.0) * CNiMath::Pi;

for (i = 0; i < SIZE; ++i)
{
for (j = 0; j < SIZE; ++j)
zData[j][i] = sin(xData[i]) * cos(yData[j]) + 2.0;
}

// Convert the native C++ double arrays to NI data types for visualization.
CNiReal64Vector xVector(SIZE, xData);
CNiReal64Vector yVector(SIZE, yData);
CNiReal64Matrix zMatrix(SIZE, SIZE, *zData);
m_graph3D.Plot3DSurface(xVector, yVector, zMatrix);

- Elton
Message 2 of 2
(3,096 Views)