필터 지우기
필터 지우기

How do we replacing empty or (NaN) cells with 0's in Matlab?

조회 수: 21 (최근 30일)
ahmed obaid
ahmed obaid 2017년 1월 16일
댓글: ahmed obaid 2017년 1월 18일
Dear experiences
i have a dataset stored in an excel file where some cells doesn't contain any values, therefore when importing or reading this data and stored it either in table or matrix .. empty cells either places in it NaN or still contain nill values .. so
first: i would like to replacing [] or NaN cells by 0's is there any code or function can do that please, i would thanks any one can give me a solution for this issue, for example when use :
data=xlread(filename), data will be view as follow
second: when importing this data using read table function, some columns are fully empty is there any function can be used to delete columns or rows if its never contain any values.. as shown in 2nd figure ..
thanks for any suggestion
---- table----
  댓글 수: 2
Image Analyst
Image Analyst 2017년 1월 16일
State what kind of data you'd prefer: A numerical matrix, or a table. And attach your workbook so we can try things.
ahmed obaid
ahmed obaid 2017년 1월 18일
ok, thanks for your interesting attached a portion data in an excel file

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

답변 (2개)

dpb
dpb 2017년 1월 16일
doc isnan
doc isempty
doc all
Look for "logical addressing"

Niels
Niels 2017년 1월 16일
편집: Niels 2017년 1월 16일
A(isnan(A))=0 % turns every NaN to zeros
to "delete" a row set the row =[]
if A(i,:)==0
A(i,:)=[]
you could use a for loope, but if you do,start from the last row
  댓글 수: 2
Guillaume
Guillaume 2017년 1월 16일
@Niels, never ever recommend to beginners the syntax
if somevector
%do something
end
Always wrap the vector in any or all depending on what is desired. There are plenty of questions on Answer which are due to the person not knowing what if does when passed a vector. In the above case:
if all(A(i, :) == 0)
A(i, :) = [];
end
And actually, do you know, without looking up the doc or testing in matlab what the output of the following is?
if [true false]
disp('test 1 passed');
end
if [true true]
disp('test 2 passed');
end
if [false false]
disp('test 3 passed');
end
if [true true true true true true false true true]
disp('test 4 passed');
end
Niels
Niels 2017년 1월 16일
y i know

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

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by