Replacing missing data with the previous data in a column
Show older comments
Hi Guys,
1.How can I replace missing data points with previous data in a column?
For example I have a set of data called 'newcycl' that has 3 columns and 6 rows each but row 3 is missing in column (:,1), I want to replace row 3 in column (:,1) with the previous value in column (:,1) , However I will like to replace missing data points all through a large pool of data this same way. lets say a 70000 by 1 matrix
newcycl(:,1) = { 0, 4, ,5,6,7 } newcycl(:,2) = { 1, 2, 3 ,4,0, 6 } newcycl(:,3) = { 2, 4, 6 ,5,6,7 }
2. Also how can I replace numbers of a set range lets say between 0 and 1 with the next higher number in a column
3. If I have a column of 9 rows, how can i divide the column into 2 columns of 4 rows each and remove the tail or pad it with the previous number
e.g. A = { 1 2 4 5 6 7 2 4 6 }
split into two columns below and remove or add to the last value so it can be divided evenly:
B = {1 2 4 5 }, C = {6,7,2,4}
Thanks guys
4 Comments
the cyclist
on 9 Aug 2019
[You might want to consider spltting this question into three separate ones. The third one in particular is pretty different. That will make it easier to keep track of different people answering different parts of your questions.]
A couple clarifying questions:
Are these values in a numeric array, or some other object (e.g. a cell array)? Your mixture of parentheses and curly brackets makes it difficult to know.
There is no such thing as a missing value in a numeric array. When you say "missing", do you actually mean zero?
Could there be multiple consecutive missing (zero) values. What do you want to do in that case? Carry forward from the last non-missing value?
Olu B
on 9 Aug 2019
the cyclist
on 9 Aug 2019
I'll ask the same question again. In what data type are your data currently stored? If it is in a numeric type, it literally cannot have a missing value.
.png)
Olu B
on 9 Aug 2019
Answers (1)
Neuropragmatist
on 9 Aug 2019
You are making cell arrays in your question by using curly {} brackets. I'm going to assume this is a mistake because you call these things matrices and not cell arrays and because the syntax you use makes me think its a mistake.
1) It sounds like you might be looking for fillmissing:
Using the 'previous' method and DIM set to columns.
2) This should work:
data; % is your data matrix
range_to_test = [0 1];
first_greater = min(data-range_to_test(2),[],2);
idx = data>range_to_test(1) & data<range_to_test(2);
new_data = idx.*first_greater;
data(idx) = new_data;
3) This should work:
n = floor(numel(A)/2);
B = A(1:n);
C = A(n+1:end);
min_length = min([numel(B) numel(C)]);
B = B(1:min_length)
C = C(1:min_length)
Hope this helps,
M.
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!