# griddata size and length mismatch error while they are the same length

40 Ansichten (letzte 30 Tage)
Bob photonics am 28 Feb. 2020
Kommentiert: darova am 1 Mär. 2020
I have this matrix that I need to interpolate, so I'm using griddata for that.
Nonetheless it keep giving me the following error:
Error using griddata (line 110)
The lengths of X and Y must match the size of Z.
The thing is I've checked all it and my "X" (yys1) and "Y"(zzs1) should be the rigth lengths for "Z"(AAA). yys1 is a 57x1 double, zzs1 is a 99x1 double, while AAA is a 57x99 double. XIT and ZIT are a new grid to which the values need to be interpolated, these are 1001x2002 double.
See the code I typed in the workspace below and the error it gives, I would appreciate any and all help ;)
>> griddata(yys1,zzs1,AAA,XIT,ZIT,'natural');
Error using griddata (line 110)
The lengths of X and Y must match the size of Z.
>> griddata(yys1,zzs1',AAA,XIT,ZIT,'natural');
Error using griddata (line 110)
The lengths of X and Y must match the size of Z.
>> griddata(yys1',zzs1,AAA,XIT,ZIT,'natural');
Error using griddata (line 110)
The lengths of X and Y must match the size of Z.
>> griddata(yys1',zzs1',AAA,XIT,ZIT,'natural');
Error using griddata (line 110)
The lengths of X and Y must match the size of Z.
>> length(yys1)
ans =
57
>> length(zzs1)
ans =
99
>> size(AAA)
ans =
57 99
Thus in otherwords I have no clue what I'm doing wrong, could someone please point out what mistake I'm making or why matlab is throwing this error?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Guillaume am 28 Feb. 2020
Bearbeitet: Guillaume am 28 Feb. 2020
"I have no clue what I'm doing wrong"
You've been caught by what I call matlab's split personality. Most functions in matlab use a row/column coordinate system but a few others use a X/Y coordinate system where X corresponds to columns and Y correspond to rows. griddata falls into the latter case and thus:
• The length of X must match the number of columns in Z
• The length of Y must match the number of rows in Z
In other words, you've got the lengths of your X and Y swapped!
##### 4 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Guillaume am 1 Mär. 2020
But my answer is good too? Right?
Not really. There was no problem with using vectors to start with. The issue is that it should have been yys1 that should have had 99 elements and zzs1 that should have been 57 element, or AAA should have been 99x57. Ultimately, you have mismatch between the y-z grid and the samples that can only be fixed by changing the grid or the samples.
darova am 1 Mär. 2020
alright then

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

darova am 28 Feb. 2020
Make yys1,zzs1,AAA the same size
[Y,Z] = meshgrid(yys1,zzs1);
AIT = griddata(Y,Z,AAA,XIT,ZIT,'natural');
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Logical finden Sie in Help Center und File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by