Greetings to you all.
I'm trying to analise some data from an ADCP (Acoustic Doppler Current Profiler). For that, i must process the data.
My matrix works on this way:
Each Row has intensity values
Each column has a certain height in relation to the bottom of the water column.
example:
0 NaN 0.5 0.3 0.7 0.9
0 NaN 0.7 0.4 0.5 0.8
0 NaN 0.9 0.1 0.4 0.5
0 NaN 1.0 0.4 0.3 0.2
The second column is equivalent a 1m height from the bottom and the instrument has not registered those values because of an error. I want to interpolate them.
Appreciate any kind of help.

 채택된 답변

Star Strider
Star Strider 2022년 4월 19일

1 개 추천

If I understand the problem correctly, use the fillmissing function across the rows —
A = [0 NaN 0.5 0.3 0.7 0.9
0 NaN 0.7 0.4 0.5 0.8
0 NaN 0.9 0.1 0.4 0.5
0 NaN 1.0 0.4 0.3 0.2];
B = fillmissing(A, 'linear', 2)
B = 4×6
0 0.2500 0.5000 0.3000 0.7000 0.9000 0 0.3500 0.7000 0.4000 0.5000 0.8000 0 0.4500 0.9000 0.1000 0.4000 0.5000 0 0.5000 1.0000 0.4000 0.3000 0.2000
The fillmissing function was introduced in R2016b.
.

댓글 수: 4

Gabriel Luca Pugliese Borges
Gabriel Luca Pugliese Borges 2022년 4월 19일
편집: Gabriel Luca Pugliese Borges 2022년 4월 19일
Hello again!
Thanks for the help, i appreciate it.
Tried using this function but it seems that it was introduced later than 2016
My pleasure!
It was introduced in R2016b.
Alternatively:
A = [0 NaN 0.5 0.3 0.7 0.9
0 NaN 0.7 0.4 0.5 0.8
0 NaN 0.9 0.1 0.4 0.5
0 NaN 1.0 0.4 0.3 0.2];
B = [interp1((0:1),A(:,[1 3]).',linspace(0,1,3),'linear').' A(:,4:end)]
B = 4×6
0 0.2500 0.5000 0.3000 0.7000 0.9000 0 0.3500 0.7000 0.4000 0.5000 0.8000 0 0.4500 0.9000 0.1000 0.4000 0.5000 0 0.5000 1.0000 0.4000 0.3000 0.2000
For whatever reason, using the entire matrix to do the interpolation did not work as I expected it to, so interpolating the first three columns and then concatenating it with the last three columns is necessary here.
.
interesting! In my real matrix i have more than 1 page, how should i proceed?
A = 112254x12x6
I was away doing other things for a few minutes.
I thought of a more efficient way to do this, as well as being able to do more than one page in one operation —
A = [0 NaN 0.5 0.3 0.7 0.9
0 NaN 0.7 0.4 0.5 0.8
0 NaN 0.9 0.1 0.4 0.5
0 NaN 1.0 0.4 0.3 0.2];
A = cat(3, A, A.*(1+randn(size(A))/100))
A =
A(:,:,1) = 0 NaN 0.5000 0.3000 0.7000 0.9000 0 NaN 0.7000 0.4000 0.5000 0.8000 0 NaN 0.9000 0.1000 0.4000 0.5000 0 NaN 1.0000 0.4000 0.3000 0.2000 A(:,:,2) = 0 NaN 0.5088 0.2997 0.7131 0.8894 0 NaN 0.7053 0.4002 0.4915 0.7957 0 NaN 0.8982 0.1012 0.3961 0.4958 0 NaN 0.9938 0.4026 0.3011 0.2003
B = A; % Copy 'A' To 'B'
B(:,2,:) = mean(B(:,[1 3],:),2) % Column 2 Is The Mean Of Colums 1 & 3
B =
B(:,:,1) = 0 0.2500 0.5000 0.3000 0.7000 0.9000 0 0.3500 0.7000 0.4000 0.5000 0.8000 0 0.4500 0.9000 0.1000 0.4000 0.5000 0 0.5000 1.0000 0.4000 0.3000 0.2000 B(:,:,2) = 0 0.2544 0.5088 0.2997 0.7131 0.8894 0 0.3526 0.7053 0.4002 0.4915 0.7957 0 0.4491 0.8982 0.1012 0.3961 0.4958 0 0.4969 0.9938 0.4026 0.3011 0.2003
The second ‘page’ or ‘A’ is a slightly altered version of the first page to demonstrate that this works, providing that a linear interpolation is desired, and the column 2 of every page is the NaN column.
.

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

추가 답변 (1개)

Keegan Carvalho
Keegan Carvalho 2022년 4월 19일
편집: Keegan Carvalho 2022년 4월 19일

1 개 추천

I'd assume "fillmissing" function would be best since you want to inteprolate the data row-wise (and this is not gridded interpolation).
Try this:
mydata = [0 NaN 0.5 0.3 0.7 0.9
0 NaN 0.7 0.4 0.5 0.8
0 NaN 0.9 0.1 0.4 0.5
0 NaN 1.0 0.4 0.3 0.2];
mydata=fillmissing(mydata,"linear",2)
% linear is one of the inteprolation methods you can use. There are others like spline, nearest, etc.
% 2 means inteprolation of data in each row of mydata. 1 - column
Hope this helps!

댓글 수: 1

Gabriel Luca Pugliese Borges
Gabriel Luca Pugliese Borges 2022년 4월 19일
편집: Gabriel Luca Pugliese Borges 2022년 4월 19일
Hello.
Thanks for the help, i appreciate it.
Tried using this function but it seems that it was introduced later than 2016
maybe you know another function

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

카테고리

도움말 센터File Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by