Azzera filtri
Azzera filtri

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

4 visualizzazioni (ultimi 30 giorni)
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 Commenti
Jan
Jan il 4 Lug 2017
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 il 4 Lug 2017
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.

Accedi per commentare.

Risposte (1)

Jan
Jan il 4 Lug 2017
Modificato: Jan il 4 Lug 2017
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.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by