How do I separate a data set into separate cell arrays according to the integer on the end of a string?
조회 수: 1 (최근 30일)
이전 댓글 표시
Lets say I have a large data set of type "cell" set out in the following way..
{[0.9335302759]} {[0.3892578745]} {[0.37648235478]} {[thing0]}
{[0.8965743754]} {[0.5945034750]} {[0.58343053465]} {[thing0]}
{[0.8965743754]} {[0.5945034750]} {[0.58343053465]} {[other0]}
{[0.9335302759]} {[0.3892578745]} {[0.37648235478]} {[thing2]}
{[0.8965743754]} {[0.5945034750]} {[0.58343053465]} {[thing4]}
{[0.8965743754]} {[0.5945034750]} {[0.58343053465]} {[other4]}
{[0.8965743754]} {[0.5945034750]} {[0.58343053465]} {[other4]}
{[0.8965743754]} {[0.5945034750]} {[0.58343053465]} {[thing49]}
{[0.8965743754]} {[0.5945034750]} {[0.58343053465]} {[other49]}
Is there a way to separate the rows corresponding to each integer on the end of the string in the 4th column into separate cell arrays? So for the data above the two values in thing0 and the one in other0 will be in a single cell array, then a 0 since nothing fell under 1, then "thing2" in another, then a 0 for 3, then "thing4" and "other4" in another, and so forth.
I'm not quite sure where to start with this.. hopefully the way I explained it makes sense.
댓글 수: 1
채택된 답변
Mohammad Sami
2020년 3월 12일
편집: Mohammad Sami
2020년 3월 12일
You need to extract the digit at the end.
% c = yourcell array
digit = regexp(c(:,4),'\d+$','match','once');
[u_d,i,j] = unique(digit);
outcell = arrayfun(@(x)c(j==x,:),i,'UniformOutput',false);
댓글 수: 5
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!