MATLAB: I keep on getting this error when I try to turn the given data into a graph

3d plotscontourcsvgraphsurface

I am really new at MATLAB but i have to turn my 3 csv files into a graph. This is my code that I cuurently have
A=importdata('mariana_depth.csv');
lon=importdata('mariana_longitude.csv');
lat=importdata('mariana_latitude.csv');
surfc(A,lon,lat);
colorbar;
And this is the error i get
Error using surfc (line 46)
The surface Z must contain more than one
row or column.
Error in Project_2_1 (line 4)
surfc(A,lon,lat);
How would I code this correctly?

Best Answer

A=importdata('mariana_depth.csv');
lon=importdata('mariana_longitude.csv');
lat=importdata('mariana_latitude.csv');
[lat_grid,lon_grid] = meshgrid(lat,lon);
figure
surfc(lat_grid,lon_grid,A);
colorbar;
Note that because of the large amount of data you have, the figure quality is not that great. (If the figure window is not very large, it appears as just a blackish blob.) The contour plot renders pretty well, though.
You could consider just using a sample of the data. For example
figure
surfc(lat_grid(1:5:end,1:5:end),lon_grid(1:5:end,1:5:end),A(1:5:end,1:5:end));
colorbar;
looks much better:
Or you could plot in sections.