How do I generate a column array starting from a specific value and with a set number of elements and stepping?

I need to generate a new array to append to an array of intensities from an EDS intensity file. The data I am given is the initial value of -40, the spacing between elements 9, and I know the number of data points is 2048. I am extremely new to MATLAB so any help is appreciated.


Solution 1:

There are several ways to initialise an array from the data you have

start = -40;
step  = 9;
n = 2048;

You could simply add an array of n multiples of step, i.e.

arr = (0:n-1)*step + start;

Or you could find the end value and make an array to meet it

stop = start + step*(n-1);
% equivalent:
arr = linspace( start, stop, n );
% or
arr = start:step:stop;

All of the above make row vectors, to get a column you can transpose them (surround with brackets and use the transpose operator .') like so:

arr = ((0:n-1)*step + start).';