Assigning a value to 0's

Hey
I have a ColumnA(108x1), this column has values when B(say) is ON. But non-zeros are present for only 104rows, 4rows are still zeros(the lousy data).
What I am trying to do is replace these 0's to a large value or NaN so that it doesn't affect my code later down. However, now Column A exists for Test 1, when B is ON. Also, I get a new ColumnA for Test 2 when B is OFF, where all rows are 0.
I was thinking of doing a cursory check for 0's at the beginning 5-10 rows and create a NewColumnA if the conditioned is satisfied. But wasn't sure how to complete it.
So, something like an "iszero" function for rows 1 to 10 should do it for a NewColumnA. Would "find", to find the number of 0's, do it?

2 commentaires

Image Analyst
Image Analyst le 4 Avr 2012
So A is nonzero for B = ON or B = OFF, and A = 0 for B = lousy data. What are the ranges of B for the 3 cases: (1) ON, (2) OFF, and (3) lousy data?
Ferd
Ferd le 4 Avr 2012
I have A, that has non-zero values when B=ON, but in the same test, when B=ON, I have some values of A as 0(bad data, measurement limitation). I have to filter out these bad data zeros. For B=OFF, A has all zeros.
For example,
B=1, A=[1,2,3,4,5,6,7,0,0,0](say), those 3 zeros have to filtered, keeping the same length.
B=0, A=[0,0,0,0,0,0,0,0,0,0], currenty using the entire array A for plots.

Connectez-vous pour commenter.

 Réponse acceptée

Honglei Chen
Honglei Chen le 4 Avr 2012

0 votes

Since ColumnA is a column, you can do
ColumnA(ColumnA==0) = nan

3 commentaires

Ferd
Ferd le 4 Avr 2012
Correct, suppose for Test 2, I need the zero's to remain as they are so I know B is OFF.
How I have my code setup is to read the ColumnA and accordingly complete plots when B is ON or OFF. But, it works only when either ColumnA is completely filled with non-zero's or zeros. But this ColumnA when B is ON(ideally it would be best for the testdata to be all non-zeros) also has a few zero's which screws up my plots.
Thanks
Honglei Chen
Honglei Chen le 4 Avr 2012
Will the following work?
if ~all(ColumnA==0)
ColumnA(ColumnA==0) = nan;
end
Ferd
Ferd le 4 Avr 2012
Yup! This is exactly what I am thought.
Now, this "NaN", would it affect calculations where B = ON (those zeros changed to NaN). I am trying it though.
Thanks Honglei!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Detection, Range and Doppler Estimation dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by