MATLAB: Seperating a colum vector into different cells.

vector seperater

Hello. Can anybody help me? I have a force vector, that i want to seperate into vector or cells, (i need to acces each part individually), that go from peak to peak according to sample nr.. I have found the sample nr. as [307 584 872], and tried this function % c=mat2cell(Force,sampnr(1,1),sampnr(1,2));
Best Regards

Best Answer

Anders - you can use the function mat2cell to break apart your column vector into cells so long as we define the dimensions of the cells. If your force vector has 1000 elements, and we want to use the peaks (or indices into the force vector) at [307 584 872], then we need to break the vector into 4 cells of sizes 307, 584-307, 872-584, and 1000-872. Note how each of these sizes (or dimensions) adds to 1000 (the total number of elements in our column vector). We supply these numbers to the mat2cell to break down the column vector
% assume 1000 elements in the vector
n = 1000;
forceVector = [1:n]';
% create the cell dimension vector
cellDims = [307 diff([307 584 872 1000])];
% break the vector into cells
peakData = mat2cell(forceVector,cellDims);
peakData is a 4x1 cell array as
peakData =
[307x1 double]
[277x1 double]
[288x1 double]
[128x1 double]
Try the above and see what happens!