Delete specific rows from a cell array and create a new cell array
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello Everyone,
I have created a 1x8 cell array from a text file. I want to create a new cell array that will only have a particular feature. If my cell array is "S" then I want to use a condition on S{8}. if any element (n) of S{8} is greater than its next element (n+1) I want to delete the entire row and after deleting all the unwanted rows, I want to create a new cell array with the remaining elements.
For example:
if I have these elements in my cell array "S"
0,0,1,0,0,0,0,10761
0,0,1,0,0,0,0,11067
0,0,1,0,0,0,0,3036687367
0,0,1,0,0,0,0,11271
.
.
0,0,0,0,0,0,0,28509
0,0,0,0,0,0,0,1656057693
0,0,0,0,0,0,0,28713
0,0,0,0,0,0,0,28815
I want to create a new cell array "T" that will only have these elements:
0,0,1,0,0,0,0,10761
0,0,1,0,0,0,0,11067
0,0,1,0,0,0,0,11271
.
.
0,0,0,0,0,0,0,28509
0,0,0,0,0,0,0,28713
0,0,0,0,0,0,0,28815
Any Suggestions?
Thanks.
0 Kommentare
Antworten (1)
dpb
am 13 Dez. 2019
Place where converting the cell array to regular double array makes sense it would seem...there's nothing in the above data that isn't numeric so just use the native double array.
S=cell2mat(S); % convert to double array
ix=[false; (diff(S(:,8))>0)]; % locations of +-ive difference
S(ix,:)=[]; % remove those rows
5 Kommentare
dpb
am 14 Dez. 2019
"Here you can see that the code has also skipped some data points (in S{1,8} Row :42 is now Row: 3 in T matrix) and many more."
No, we can't see anything of the sort. What does "the code has skipped some data points" mean? It deleted everything for which diff(S)>0 as per the original specification--that there are duplicated values and therefore a set of points for which the difference is now zero isn't anything that was given as a requirement.
Would have to see all the original data to know; perhaps the condition should be
ix=[false; (diff(T(:,8))>=0)];
but can't tell without a definitive statement of what is the desired result; some heuristic that may work for a given dataset isn't a specification.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!