필터 지우기
필터 지우기

how to remove the last and before the last element from cell?

조회 수: 4 (최근 30일)
skysky2000
skysky2000 2017년 7월 4일
편집: Image Analyst 2017년 7월 4일
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
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
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
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.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by