cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

SOLVED
Highlighted

## Error creating matrix of 2 variable function - subsequently create contour plot

I am having issues creating a matrix of values from a 2 variable function and then plotting the matrix data in a contour plot.

Short script is attached; any input would be very appreciated.

Regards,

T.S.

Tags (4)
1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Error creating matrix of 2 variable function - subsequently create contour plot

The matrix function always starts at 0,0, so you get a divide by zero. You would also end up with a very large matrix: more than 7 million elements.

Use the CreateMesh function instead. It is designed for exactly this.

4 REPLIES 4

## Re: Error creating matrix of 2 variable function - subsequently create contour plot

The matrix function always starts at 0,0, so you get a divide by zero. You would also end up with a very large matrix: more than 7 million elements.

Use the CreateMesh function instead. It is designed for exactly this.

## Re: Error creating matrix of 2 variable function - subsequently create contour plot

Two other ways, but the second is by no means recommend.

1) Directly plot Deltasigma. In case of your function you can set the ranges for x and z so that the function will evaluate (I chose 0.0001 to 1959 for both)

2) create a new function Deltasigma2 which is ident with Deltasigma but will return 10^5 (or any other value) in case of an error using the onerror construct. You could use it with your approach but for reasons Richard already mentioned it would not be adviseable.

## Re: Error creating matrix of 2 variable function - subsequently create contour plot

Thanks Richard. That was very helpful and exactly what I was looking for. I am sure this has been answered on a previous post, but is there a way to reverse the scale on the vertical axis so that my data is visually correct when plotting data with increasing depth?

Regards,

T.S.

## Re: Error creating matrix of 2 variable function - subsequently create contour plot

In general, no, but in your case you can make the depths negative, from -1 to -BT.