Input coordinates cannot be complex.

조회 수: 10 (최근 30일)
Christabelle Tonna
Christabelle Tonna 2019년 8월 3일
댓글: Star Strider 2019년 8월 3일
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.

채택된 답변

Star Strider
Star Strider 2019년 8월 3일
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
Christabelle Tonna
Christabelle Tonna 2019년 8월 3일
This actually solved it for me. Thanks a lot!
Star Strider
Star Strider 2019년 8월 3일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by