explain x=[65 65 75 75]; in matlab

The code x=[65 65 75 75]; in MATLAB creates a 1-dimensional array/vector named x which contains four elements. The four elements of x are 65, 65, 75, and 75. This is equivalent to executing the following code:

main.m
x = zeros(1,4);
x(1) = 65;
x(2) = 65;
x(3) = 75;
x(4) = 75;
60 chars
6 lines

Alternatively, you can define x using the repmat function as:

main.m
x = repmat([65 75], 1, 2);
27 chars
2 lines

This creates a 1-row, 4-column matrix where the first two elements are 65 and the second two elements are 75.

related categories

gistlibby LogSnag