I keep on getting this error when I try to turn my given data into a graph

조회 수: 1 (최근 30일)
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?
  댓글 수: 2
the cyclist
the cyclist 2020년 4월 4일
편집: the cyclist 2020년 4월 4일
Can you upload your data in a MAT file (using the paper clip icon)? If not, can you at least report the values of
size(A)
size(lon)
size(lat)
Michelle
Michelle 2020년 4월 4일
the files are too large but the values are
A
1320x1440 matrix
lon
1440x1 matrix
lat
1320x1 matrix

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2020년 4월 4일
편집: the cyclist 2020년 4월 4일
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.
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 4월 4일
I always recommend using 'edgecolor', 'none' when drawing surface plots. If you use shading then it automatically turns off the edge color.
the cyclist
the cyclist 2020년 4월 5일
편집: the cyclist 2020년 4월 5일
That's a good tip. Here's OP's plot with full data.
Depending on your purpose here, you might want to use the contour plot as well, which makes some of the structure clearer:

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

the cyclist
the cyclist 2020년 4월 4일
편집: the cyclist 2020년 4월 4일
I can guess at a couple problems here, and I'm also going to guess that you didn't really study the documentation for surfc, to understand the inputs.
First, I expect you want A to be the third input, since it is the depth (corresponding to the Z input in the documentation).
Second, I'm guessing that your variables are just three vectors. As can be seen in the examples in the documentation, you need to form the inputs into a grid. The meshgrid command is handy for that.
I'll leave it at that, and wait on your reply (and perhaps the data).

Walter Roberson
Walter Roberson 2020년 4월 4일
In some cases, the data forms an implicit grid.
For example if your longitude repeated every 5 values and your latitude had 5 copies of every value in a row, then that would be data for a implicit grid that was 5 by something.
In such cases, when you identify the repeat period, you can reshape() the lat, lon, and A values according to the repeat period, in order to get a 2D array. In some cases you might need to reshape() with the period in the other position than you expect and transpose the result. For example,
reshape(lon, 5, [])
versus
reshape(lon, [], 5).'
However, in other cases, there is no implicit grid. There might be an approximation of a grid, such as you might get if you did not bother to put in any entries for locations that were on land, but using reshape() only works if there is a full implicit grid. In such cases, use scatteredInterpolant() and invoke it on a grid of locations to sample at:
F = scatteredInterpolant(lon, lat, A);
N = 100;
lonv = linspace(min(lon), max(lon), N);
latv = linspace(min(lat), max(lat), N);
[lonG, latG] = ndgrid(lonv, latv);
Ainterp = F(lonG, latG);
surf(lonG, latG, Ainterp)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by