Replacing missing data with the previous data in a column

조회 수: 3 (최근 30일)
Olu B
Olu B 2019년 8월 9일
댓글: Olu B 2019년 8월 9일
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
the cyclist
the cyclist 2019년 8월 9일
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.
Messages Image(3526219204).png
Olu B
Olu B 2019년 8월 9일
It is a numeric type and was stored in a csv format from a picolog file.
OK.. is there a way you can replace all the zeros in a column with the previous number non zero number in the same column?

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

답변 (1개)

Neuropragmatist
Neuropragmatist 2019년 8월 9일
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.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by