Trimming Null Characters off a multi-dimensional cell array

조회 수: 1 (최근 30일)
Bryce Johnson
Bryce Johnson 2019년 6월 10일
댓글: dpb 2019년 6월 11일
I'm trying to trim the null characters off a multi-dimensional cell array that looks like this:
A={'a','b','c'; ----> desired output A={'a','b','c';
't','y',[]; 't','y',[];
[],'z',[]; [],'z',[];}
[],[],[];
[],[],[]}
When I use A(~cellfun('isempty',A)) I end up getting back a colum vector of everything but the null characters. I understand I could probably just use a for loop to find the longest column, then cut it from there, however I may be taking in a lot of data and my code is already quite slow, so I was wondering if there was any elegant/fast solutions to this problem?

채택된 답변

dpb
dpb 2019년 6월 10일
>> A(any(~cellfun(@isempty,A),2),:)
ans =
3×3 cell array
{'a' } {'b'} {'c' }
{'t' } {'y'} {0×0 double}
{0×0 double} {'z'} {0×0 double}
>>
  댓글 수: 4
Bryce Johnson
Bryce Johnson 2019년 6월 11일
Oh I see now, I tought that was a smiley face for some reason! Thank you for your intuitive explanation it will definelty help me when solving problems like this in the future!
dpb
dpb 2019년 6월 11일
Would seem then you're still at the learning level that spending some time working thru the excercises at the Getting Started link in the documentation would pay back many times over on time invested...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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