Seperating a colum vector into different cells.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Anders Mahler
el 5 de Sept. de 2014
Comentada: Abe
el 26 de Dic. de 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
0 comentarios
Respuesta aceptada
Geoff Hayes
el 5 de Sept. de 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 comentario
Abe
el 26 de Dic. de 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.
Más respuestas (2)
Michael Haderlein
el 5 de Sept. de 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)]));
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!