Vector size is simply the number of elements in the vector:
Current vector size is queried by size() member function. Convenience empty() function returns true if size is 0:
vector<int> v = { 1, 2, 3 }; // size is 3
const vector<int>::size_type size = v.size();
cout << size...
MATLAB code can be saved in m-files to be reused. m-files have the .m extension which is automatically associated with MATLAB. An m-file can contain either a script or functions.
Scripts
Scripts are simply program files that execute a series of MATLAB commands in a predefined order.
Scripts do no...
The data.table package provides a convenient way to group by runs in data. Consider the following example data:
library(data.table)
(DT <- data.table(x = c(1, 1, 2, 2, 2, 1), y = 1:6))
# x y
# 1: 1 1
# 2: 1 2
# 3: 2 3
# 4: 2 4
# 5: 2 5
# 6: 1 6
The variable x has three runs: a run ...
DT[where, select|update|do, by] syntax is used to work with columns of a data.table.
The "where" part is the i argument
The "select|update|do" part is the j argument
These two arguments are usually passed by position instead of by name.
Our example data below is
mtcars =...
<PROJECT_ROOT>\app\build.gradle is specific for app module.
<PROJECT_ROOT>\build.gradle is a "Top-level build file" where you can add configuration options common to all sub-projects/modules.
If you use another module in your project, as a local library you would have another...
R is able to access the current date, time and time zone:
Sys.Date() # Returns date as a Date object
## [1] "2016-07-21"
Sys.time() # Returns date & time at current locale as a POSIXct object
## [1] "2016-07-21 10:04:39 CDT"
as.numeric(Sys...
To start coding in the first place, you have to right click your VBA Project in the left list and add a new Module.
Your first Hello-World Code could look like this:
Sub HelloWorld()
MsgBox "Hello, World!"
End Sub
To test it, hit the Play-Button in your Toolbar or simply hit the...
Approximate-number data types for use with floating point numeric data.
SELECT CAST( PI() AS FLOAT) --returns 3.14159265358979
SELECT CAST( PI() AS REAL) --returns 3.141593
Data types that represent monetary or currency values.
Data typeRangeStoragemoney-922,337,203,685,477.5808 to 922,337,203,685,477.58078 bytessmallmoney-214,748.3648 to 214,748.36474 bytes
Binary data types of either fixed length or variable length.
Syntax:
BINARY [ ( n_bytes ) ]
VARBINARY [ ( n_bytes | max ) ]
n_bytes can be any number from 1 to 8000 bytes. max indicates that the maximum storage space is 2^31-1.
Examples:
SELECT CAST(12345 AS BINARY(10)) -- 0x0000000000000000...
String data types of either fixed length or variable length.
Syntax:
CHAR [ ( n_chars ) ]
VARCHAR [ ( n_chars ) ]
Examples:
SELECT CAST('ABC' AS CHAR(10)) -- 'ABC ' (padded with spaces on the right)
SELECT CAST('ABC' AS VARCHAR(10)) -- 'ABC' (no padding due to variable character)
SELE...
UNICODE string data types of either fixed length or variable length.
Syntax:
NCHAR [ ( n_chars ) ]
NVARCHAR [ ( n_chars | MAX ) ]
Use MAX for very long strings that may exceed 8000 characters.
Long vectors with long runs of the same value can be significantly compressed by storing them in their run-length encoding (the value of each run and the number of times that value is repeated). As an example, consider a vector of length 10 million with a huge number of 1's and only a small number o...
The Default keyword is used to execute an action when no other conditions match the input value.
Example:
switch('Condition')
{
'Skip Condition'
{
'First Action'
}
'Skip This Condition Too'
{
'Second Action'
}
Default
{
'Default Action'
}
}
Output:
D...
The Arbitrary class is for types that can be randomly generated by QuickCheck.
The minimal implementation of Arbitrary is the arbitrary method, which runs in the Gen monad to produce a random value.
Here is an instance of Arbitrary for the following datatype of non-empty lists.
import Test.QuickC...
% Define serial port with a baud rate of 115200
rate = 115200;
if ispc
s = serial('COM1', 'BaudRate',rate);
elseif ismac
% Note that on OSX the serial device is uniquely enumerated. You will
% have to look at /dev/tty.* to discover the exact signature of your
% serial device
...