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일
Y(1:numel(X))

추가 답변 (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