Seperating a colum vector into different cells.
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Geoff Hayes
2014-9-5
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 个评论
Abe
2014-12-26
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.
更多回答(2 个)
Michael Haderlein
2014-9-5
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!