Replacing missing data with the previous data in a column

3 Ansichten (letzte 30 Tage)
Olu B
Olu B am 9 Aug. 2019
Kommentiert: Olu B am 9 Aug. 2019
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 Kommentare
the cyclist
the cyclist am 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.
Messages Image(3526219204).png
Olu B
Olu B am 9 Aug. 2019
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Neuropragmatist
Neuropragmatist am 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.

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by