Seperating a colum vector into different cells.
조회 수: 4 (최근 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에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!