Operator Missing

Hi

i want to concatenate one matrix 3x3 and a string array 1x3 (both taken from a excel spreadsheet) in order to create a matrix 3x3 with their names , i am triying to replicate the command xlsread in matlab, following is the code

» m= xlsreadm("bb","a2:c4",1,2);
» names= spreadsheetreadSA("bb","a1:c1",1);
» d= m|names;
 then i get (0) : error G0064 : Operand missing 

i don´t know what i am doing wrong

can you help me ?

1 Answer



0



You have some options of how you keep numeric data and character data together.

Inserting character data into a matrix
GAUSS does allow you to add character data into a matrix. GAUSS does this by actually placing the characters inside the memory that is allocated for a single numeric matrix element. Since this size is 8 bytes and a character takes up 1 byte, when you place character data into a matrix element, you only have room for 8 characters. Here is a simple example:

//Create a 1x2 string array
var_names = "height" $~ "weight";

//Create a 1x2 row vector
data = { 73 184 };

//Convert 'var_names' to a character vector (char data inside a matrix)
var_names = satocv(var_names);

//Concatenate the new 'var_names' on top of 'data'
data = var_names | data;

//Printing character data requires the '$' operator
print $data[1,.];

//Print numeric portion
print data[2,.];

That is not necessarily recommended, but it will work as described.
Creating a structure
Another method is to create a structure. A structure is a variable that can hold many different variables of different types. You can choose what is allowed in your structure and what each member is called. For example, if we want to create a structure to hold some observations of a couple of variables, we may want one member to be a string array to hold the variable names and another to be a matrix to hold the data, like this:

//Create structure which will hold
//variable names and data
struct my_data {
   string array names;
   matrix x;
};

Now my_data is like a blueprint for creating a specific variable which we said can hold one string array and one matrix. The next step is to create one of these my_data structures. We do that by declaring a variable to be a my_data structure, like this:

//Declare 'wine' to be a 'my_data' structure
struct my_data wine;

Now that we have a my_data structure, we can add data to it by using the 'dot' operator to access the members like this:

//Add variable names
wine.names = "age" $| "alcohol content" $| "price";

//Add numeric data for one observation
wine.x = { 4 12.8 15.95 };

print wine.names;
print wine.x;

aptech

1,773

Your Answer

1 Answer

0

You have some options of how you keep numeric data and character data together.

Inserting character data into a matrix
GAUSS does allow you to add character data into a matrix. GAUSS does this by actually placing the characters inside the memory that is allocated for a single numeric matrix element. Since this size is 8 bytes and a character takes up 1 byte, when you place character data into a matrix element, you only have room for 8 characters. Here is a simple example:

//Create a 1x2 string array
var_names = "height" $~ "weight";

//Create a 1x2 row vector
data = { 73 184 };

//Convert 'var_names' to a character vector (char data inside a matrix)
var_names = satocv(var_names);

//Concatenate the new 'var_names' on top of 'data'
data = var_names | data;

//Printing character data requires the '$' operator
print $data[1,.];

//Print numeric portion
print data[2,.];

That is not necessarily recommended, but it will work as described.
Creating a structure
Another method is to create a structure. A structure is a variable that can hold many different variables of different types. You can choose what is allowed in your structure and what each member is called. For example, if we want to create a structure to hold some observations of a couple of variables, we may want one member to be a string array to hold the variable names and another to be a matrix to hold the data, like this:

//Create structure which will hold
//variable names and data
struct my_data {
   string array names;
   matrix x;
};

Now my_data is like a blueprint for creating a specific variable which we said can hold one string array and one matrix. The next step is to create one of these my_data structures. We do that by declaring a variable to be a my_data structure, like this:

//Declare 'wine' to be a 'my_data' structure
struct my_data wine;

Now that we have a my_data structure, we can add data to it by using the 'dot' operator to access the members like this:

//Add variable names
wine.names = "age" $| "alcohol content" $| "price";

//Add numeric data for one observation
wine.x = { 4 12.8 15.95 };

print wine.names;
print wine.x;

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy