Input coordinates cannot be complex.

I am trying to calculate the surface area of a plot generated using surf. I am using the function surfarea attached. I keep getting the error Input coordinates cannot be complex when executing griddata. None of the coordinates in the file are complex. The file is too large to attach so I am including an extract image. The file is downloadable at https://we.tl/t-mfKxV2RFQ3 . Can anyone indicate a potential reason please?
clc;
clear variables;
T=readtable('C:\Users\CT\Desktop\Matlab Question\Surface.dat');
x=T(:,1);
y=T(:,2);
z=T(:,3);
[X,Y] = meshgrid(0:1:2455, 0:1:1848);
Z = griddata(x,y,z,X,Y);
h = surf(X,Y,Z);
[totalArea] = surfarea(h);
shading interp;
xlabel('x'), ylabel('y'), zlabel('z'),colorbar
title(sprintf('Total surface area: %.2f', surfarea(h)));
view(60,30);
saveas(h, 'C:\Users\CT\Desktop\Matlab Question\Surface.png');
Update:
The code works fine when using
T=xlsread('C:\Users\CT\Desktop\Matlab Question\Surface.xlsx', 1);
instead of readtable. However I cannot import data from Excel as the original data file contains 10.9 million rows.

 Respuesta aceptada

Star Strider
Star Strider el 3 de Ag. de 2019

1 voto

If you can read the entire file with readtable and you simply want the data in the table, consider using the table2array function to convert your table columns to a double array.
I have no idea what the problem could be with complex values and griddata, especially if your code works with xlsread.

2 comentarios

Christabelle Tonna
Christabelle Tonna el 3 de Ag. de 2019
This actually solved it for me. Thanks a lot!
Star Strider
Star Strider el 3 de Ag. de 2019
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by