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

1 回表示 (過去 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 Center および File ExchangeDirection of Arrival Estimation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by