how to remove the last and before the last element from cell?
4 次查看(过去 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!