Assigning actual distance to a matrix

I have a 100 x 100 matrix of values (water depths). The water depths are in metres, however the x and y values are arbitrary units with no assigned distance.
How can I alter the matrix so that the x and y axes correspond to actual distance? Suppose the actual width of the sampled site is 50km X 50km - so the grid cells are 0.5km apart.
THANK YOU!

Answers (4)

Use meshgrid to set up the actual distances
[xx yy] = meshgrid(0.5:.5:50);
mesh(xx,yy,magic(100))
Above I wasn't sure what you want to do at the boundaries (0-49.5 or 0.5-50 so I did 0.5 to fifty at 0.5 increment.
To create the grid for x and y axis is easy. What is your actual data sample look like?
x=0:0.5:50;
y=0:0.5:50
You can't. There is not method to insert the distances in the matrix. Perhaps you want two other matrices containing the X- and Y-positions repectively. Then you can create a [100 x 100 x 3] array, which contains the different information in three "layers":
Z = rand(100, 100);
X = repmat(0.5:0.5:50, 100, 1);
Y = repmat(transpose(0.5:0.5:50), 1, 100);
M = cat(3, Z, X, Y);
But as long as the X- and Y-positions are very redundant, I cannot imagine, what this might be useful for.
Please explain, what you want to achieve.
philippa
philippa on 25 Aug 2011
The data set is a bathymetry data of an oceanic volcano (so picture a surf plot with a volcano in the centre). I need to calculate slope angles (using the gradient function) but in order to do so, the units along my horizontal axes need to correspond to the vertical axes. I am modelling sediment transport thus need to know horizontal distances.
Would this change your answers?
Thanks

2 Comments

I am lost. What do you mean "the x and y values are arbitrary units with no assigned distance."? You have 100x100 water depth data. Do you mean you don't have x and y data for all those 10000 points? All you know is that those data are measured at a 50km by 50km square equally with 0.5km interval?
Mine was just for plotting.
Can't you just take the gradient of the matrix and then multiply by a scaling factor?

Sign in to comment.

Asked:

on 25 Aug 2011

Community Treasure Hunt

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

Start Hunting!