create a vector with a certain size with only the entry 800 in matlab

To create a vector with a certain size and initialize all its entries to a particular value, such as 800 in this case, we can make use of the function ones(). The ones() function creates an array of ones having the same size as the input size.

Here's the code to create a vector of size n with all entries equal to 800.

main.m
n = 10; % size of vector
x = ones(1, n) * 800;
47 chars
3 lines

This creates a row vector that is 1xn, filled with the value 800.

related categories

gistlibby LogSnag