Assigning actual distance to a matrix
Show older comments
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)
Sean de Wolski
on 25 Aug 2011
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.
Fangjun Jiang
on 25 Aug 2011
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
Jan
on 25 Aug 2011
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
on 25 Aug 2011
0 votes
2 Comments
Fangjun Jiang
on 25 Aug 2011
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?
Sean de Wolski
on 25 Aug 2011
Mine was just for plotting.
Can't you just take the gradient of the matrix and then multiply by a scaling factor?
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!