Subtracting surface from 2D array of values

조회 수: 6 (최근 30일)
Maddie Harasyn
Maddie Harasyn 2017년 7월 20일
편집: Maddie Harasyn 2017년 7월 21일
Hello,
My main goal is to correct a DEM with distortion. The distortion appears to match a parabolic shape, so therefore I was planning on generating a 2-D surface which best fits the elevation data, and then subtract this from the whole data set to get a 'corrected' elevation model.
I have converted the elevation model into an ASCII .txt file, and have imported that into MATLAB using the 'arcgridread' fn, which imports the data as a 2-D array. I have removed the first column of the data, as this contained NaN values. I have then specified x and y variables to go into the 'fit' fn (am unsure if I have done this correctly, see below). I would then like to take that fitted surface, and subtract it from the 2-D array, to get the corrected ASCII .txt table. I was thinking that converting the surface to a matrix with the same dimensions as my ASCII could be a solution?
This is what my script looks like so far:
[Z, R] = arcgridread('ascii.txt');
Z = Z(:,2:end); %removes first column of NaN values from array
x = Z(:,1:2);
y2 = Z(1,1:1161);
y = y2';
surf = fit(x, y, 'poly22');
Thanks!
  댓글 수: 1
Image Analyst
Image Analyst 2017년 7월 21일
Which fit() are you using:
Statistics and Machine Learning Toolbox
NaiveBayes.fit - Create Naive Bayes classifier object by fitting training data
LinearModel.fit - Create linear regression model
gmdistribution.fit - Gaussian mixture parameter estimates
NonLinearModel.fit - Fit nonlinear regression model
LinearMixedModel.fit - Fit linear mixed-effects model using tables
GeneralizedLinearModel.fit - Create generalized linear regression model
and you can't assign surf to something. surf() is a built in function. You send values INTO surf(), you do not overwrite surf() with results of some function you call fit(). Doing that will not call surf(), it will just destroy the built-in surf function with the results of your other function.

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

채택된 답변

Matt J
Matt J 2017년 7월 20일
편집: Matt J 2017년 7월 21일
I think you're trying to do,
surfFit = fit(x, y, 'poly22');
y_corrected = y - surfFit(x(:,1), x(:,2));
  댓글 수: 1
Maddie Harasyn
Maddie Harasyn 2017년 7월 21일
편집: Maddie Harasyn 2017년 7월 21일
I was playing around, and I was actually able to achieve the output I wanted using a for loop, which corrected for each row in the array separately. Not ideal for very large data sets, but worked in my case! Thanks for your help.
I've included my code, in case others are interested.
[Z, R] = arcgridread('survey3_ascii.txt');
Z = Z(:,2:end); %removes first column of NaN values from array
m = size(Z,1); %number of rows in array
for j = 1:m;
nx = size(Z,2);
x = 1:nx;
p = polyfit(x,Z(j,:),2);
y = polyval(p,x);
Z(j,:) = Z(j,:) - y;
end
figure;
imagesc(Z);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discriminant Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by