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

11 views (last 30 days)
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

Accepted Answer

madhan ravi
madhan ravi on 26 Sep 2019
Y(1:numel(X))

More Answers (1)

Ankit
Ankit on 26 Sep 2019
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

Community Treasure Hunt

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

Start Hunting!