Effacer les filtres
Effacer les filtres

Seperating a colum vector into different cells.

1 vue (au cours des 30 derniers jours)
Anders Mahler
Anders Mahler le 5 Sep 2014
Commenté : Abe le 26 Déc 2014
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

Réponse acceptée

Geoff Hayes
Geoff Hayes le 5 Sep 2014
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!
  1 commentaire
Abe
Abe le 26 Déc 2014
This is very nice code, but pls I want to work with it by rate for example the persantage going up if the string of numbers become bigger. More precislly we have string its length is 2^5 so the string will be divided to 5 parts, each part has different rate (1/5, 2/5, 3/5, 4/5 and 5/5). if you have any ideas about this that will be helpful.

Connectez-vous pour commenter.

Plus de réponses (2)

Michael Haderlein
Michael Haderlein le 5 Sep 2014
Star Strider's solution will have the last value of fvc{n} to be the first value of fvc{n+1}. Is that intended? I understand the question the way that no value is repeated and the fv vector is just split into the fractions. Then it goes quite simple with
fc=mat2cell(fv,1,diff([0 fvd length(fv)]));

Anders Mahler
Anders Mahler le 7 Sep 2014
Thanks for the Answers, helped a lot.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by