Writing a function for an interpolation method

Hello all
I wonder if someone could help me. I've been writing a function to use a certain type of interpolation method. The 2D section of it works, however I'm having a problem with the 3D part of it. My supervisor has also edited it and we're still getting an error. I've attached the function and my test script. The error we keep getting is:
Output argument "output" (and maybe others) not assigned during call to "interp_azonal3Dv2".
Error in test (line 55)
[vel_test] =interp_azonal3Dv2(x,y,sigloc,lvls,tri,vel); % 6 variables
Any help is much appreciated :)
P.s. you won't be able to run the function because it calls on data that I can't post on this website.

7 Kommentare

Andreas Brinch Nielsen
Andreas Brinch Nielsen am 19 Jan. 2017
Bearbeitet: Andreas Brinch Nielsen am 19 Jan. 2017
If all([e1,e2,e3]) ~= 0 you don't specify the output.
This propably happens because you meant to delete an "end" in line 102 and add it to the end of the file.
If you delete the ... in the end of if and for lines, the indentation can be automatically adjusted which will show you these kinds of errors.
Meghan
Meghan am 19 Jan. 2017
It specifies that output=Field(i)?
Also I changed the end on line 102 after I posted this and I am still getting the error above.
Simple way to solve this error is just to put
output = [];
right at the top of your function. Of course this will just lead you to a new error because presumably your calling code is not expecting to ever get [] from calling the function so you will still have to work out which path of your function is failing to assign anything to 'output'.
Your code looks like this:
narg==6
...
if all([e1,e2,e3]) == 0 ,...
output = field(i);
else
x0c = xloc - xc(i);
y0c = yloc - yc(i);
end
If the if condition does not equal to true, it is not set. If you move the "end" from line 102 to the end, it should be set later on, but not as the code was posted.
Meghan
Meghan am 19 Jan. 2017
Bearbeitet: Meghan am 19 Jan. 2017
Thanks, I changed it so that an end was moved to the bottom of the function. However I'm still getting the error. Its very frustrating because I know its probably something really small that's causing it and I just can't figure it out! I've attached the updated version.
Now it is not set when the following line equals to true:
if length(lvls)==kbm-1; %!da
Again, auto indent your whole script. This helps you finding these errors. Also, a simple line by line debugging would also show you exactly what is happening.
Meghan
Meghan am 19 Jan. 2017
Thanks for the help. I actually changed a few things around and now it works :)
Such effort for such tiny errors!

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 19 Jan. 2017

Kommentiert:

am 19 Jan. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by