How do I delete empty array among populated arrays?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
I have trial names that end with numbers e.g. _1 or _30. The number suffix does not increment by _1, _2, _3 etc because I am only reading a few one minute trials over a thirty minutes of data. If the condition is 30 minutes, then the data from these trials is being stored in a 1x30 structure even though 2-29 is empty because I am only reading in two trials; the data is written to a .mat file. Without changing the trial name, is there a function in MATLAB that only stores arrays that are populated.
I tried doing this:
tnum = str2num(fname(jtnum+1:j)); % trial number if there is one
tnum = tnum(~cellfun(@isempty,tnum));%keeps only populated cells
But I get an error saying: Input #2 expected to be a cell array, was double instead.
Therefore, I added a second line of code, tnum = mat2cell(tnum) to try and get around the error "error to be cell array..." but got an error saying "Matrix indices must be full double."
Any suggestion is much appreciated.
Eric
댓글 수: 6
Jan
2013년 9월 17일
Thanks for the clarifications.
If fname is a string, str2num replies a number, which is stored in tnum. Then cellfun(@isempty, tnum) does not work, because tnum is not a cell, but a number.
The comment "keeps only populated cells" does not enlighten me concerning the purpose of this line. Because you check the emptiness of tnum in the IF command later, what about simply omitting the the complete "tnum = tnum(~cellfun(@isempty,tnum));" line?
답변 (1개)
Doug Hull
2013년 9월 16일
You are probably better off not having variables named like this in the first place.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!