how to remove the last and before the last element from cell?
조회 수: 1 (최근 30일)
이전 댓글 표시
Dear all, I have cell
a= {[5] [130 12] [130 9 67 66 2] [34 45 21] [55 6 77 8 12 343 ]}
1- how to remove the extract the last element? b=[343 21 2 12 5];
2- how to extract the element before the last? c=[12 45 66 130]
3- how to remove both of them from each cell? f={[] [] [130 9 67 ] [34 ] [55 6 77 8 ]}
Thanks in advance
댓글 수: 2
Jan
2017년 7월 4일
This sounds like a homework question. Is this true? Then please mention this, because the forum will not solve your homework for good reasons. Note that you could not provide a solution copied from the forum without cheating.
Please post, what you have tried so far and explain, which problems occur. Then an assistance is okay.
Adam
2017년 7월 4일
It sounds more like a design that has gone wrong and is now trying to solve an ugly problem to get to some 'useful' result as a consequence, to me.
답변 (1개)
Jan
2017년 7월 4일
편집: Jan
2017년 7월 4일
Run a loop over the elements of the cell (the output b looks like you want it flipped?):
for k = numel(a):-1:1
b(numel(a) - k + 1) = ...
end
Now use end and a{k} to get the last element of each vector.
The second last element works equivalently, but check at first if the vectors have more than 1 element by if length(a{k} >= 2).
Try it and post a specific question, if you have one.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!