I keep on getting this error when I try to turn my given data into a graph
Mostra commenti meno recenti
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 Commenti
the cyclist
il 4 Apr 2020
Modificato: the cyclist
il 4 Apr 2020
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
il 4 Apr 2020
Risposta accettata
Più risposte (2)
the cyclist
il 4 Apr 2020
Modificato: the cyclist
il 4 Apr 2020
0 voti
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).
1 Commento
Michelle
il 4 Apr 2020
Walter Roberson
il 4 Apr 2020
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)
Categorie
Scopri di più su Vector Fields in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


