Delete specific numbers from cell array

조회 수: 10 (최근 30일)
Marie P.
Marie P. 2020년 11월 18일
답변: madhan ravi 2020년 11월 18일
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
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
Marie P.
Marie P. 2020년 11월 18일
No it cant because I loose a lot of values when I have some zeros within my data.
When I calculate the diff(log(data), I get an Inf or -Inf value from value to zero and from zero to value. When I firstly clear my data from the zeros, I avoid that.

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

채택된 답변

KALYAN ACHARJYA
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
Marie P.
Marie P. 2020년 11월 18일
When I use that on the into cells transformed data I get again "Operator '==' is not supported for operands of type 'cell'."
And If I use it on the matrix data, I get a cell where the data is stored(?) but can't see the values itself. May be a dumb question but how do I see the data itself and can work with it?

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

추가 답변 (1개)

madhan ravi
madhan ravi 2020년 11월 18일
p2 = [1, 2; 0, 1]
p2 = 2×2
1 2 0 1
p3 = num2cell(p2, 1);
Wanted = cellfun(@nonzeros, p3, 'un', 0)
Wanted = 1x2 cell array
{[1]} {2×1 double}

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by