Delete specific numbers from cell array
조회 수: 4 (최근 30일)
이전 댓글 표시
I have a 1801 x 20 data matrix where one column is one set of data. I need to calculate the log diff and I I actually wanted to clear each column from the zeros, but each column has a different amount of zeros within the data (which is not possible in a matrix). I did this so far:
p3=num2cell(p2) ;
p3(p3==0)=[];
or:
p3(cellfun(@(p3==0)=[];
But both didnt work.
댓글 수: 2
Mathieu NOE
2020년 11월 18일
hello Marie
why converting to cell array ? the test can be done directly on the nimeric data , column wise
regards
채택된 답변
KALYAN ACHARJYA
2020년 11월 18일
result=cell(1,20);
for i=1:20
data=p2(:,i);
data(data==0)=[];
result{i}=data;
end
result
The result is a cell array, whose individual elements having coloum of the p2 martix without zero. Hence individual cell elements will have different length after zero deletion.
추가 답변 (1개)
madhan ravi
2020년 11월 18일
p2 = [1, 2; 0, 1]
p3 = num2cell(p2, 1);
Wanted = cellfun(@nonzeros, p3, 'un', 0)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!