Input coordinates cannot be complex.
7 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!