how to delete cells in a cell array, such that it has the same length as one of my other arrays

7 次查看(过去 30 天)
I am trying to delete cells in a cell array, such that is has the same length as one of my other arrys
I have a cell array of 23x1 cell which cotains numbers (all different ones) --> call it X
X =
2223
2338
3449
3599 and so on
I have another cell aray of 24x 1 cell which contains numbers as well (the same number in every cell) --> call it Y
Y =
2222
2222
2222
2222
2222 and so on
I want that my Y variable gets the same length as my X variable, by removing one of the cells in this cell array.
How can I program this? As they will differ in length and I need to do this multiple times, I probably need something with length or numel.
I tried several things, but none is working yet.
Hope you can help me out.
Best,
Joyce

采纳的回答

madhan ravi
madhan ravi 2019-9-26

更多回答(1 个)

Ankit
Ankit 2019-9-26
There are different ways in which you can delete an element from your array
Case 1: If you want to delete an specific element
idx = index
a(idx) = []
Case 2: If you want to delete elements which have same value for e.g. 2
a = [1,2,3,2,5];
a(a == 2) = []
and other way as mentioned by madhan ravi

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by