Surf plot from excel file

3 views (last 30 days)
Nathan
Nathan on 8 Mar 2024
Answered: Star Strider on 8 Mar 2024
I am unsure on how to get this to upload to produce a surface plot. I have seen similar code such as the below but am unsure on how to convert this to function with mine
clc
clear all
T = readmatrix('C:\Users\natha\Downloads')
x = T(:,1)
y = T(:,2)
z = T(:,3)
[X,Y]=meshgrid(x,y)
surf(X,Y,z)
xlabel('X')
ylabel('Y')
zlabel('IDT Resonant Frequency')

Answers (1)

Star Strider
Star Strider on 8 Mar 2024
It would help to know what the data are, and what you want to do with the NaN values.
That aside, just plot all but the first column as a matrix —
A1 = readmatrix('IDT results.xlsx')
A1 = 17×10
1.0000 NaN -10.7900 -10.7000 -10.8700 -11.4100 -12.1600 -12.5300 -12.2800 -11.5000 2.0000 -11.7000 -11.2000 -11.0700 -11.4700 -12.0000 -12.5500 -12.3000 -11.0400 NaN 3.0000 NaN -12.3000 -11.9000 -12.0000 -12.2000 -12.3900 -12.5000 -12.2500 -11.0400 4.0000 -13.9000 -13.2100 -13.1500 -13.2000 -12.8700 -12.8700 -12.2700 -11.8600 NaN 5.0000 NaN -14.9300 -14.5000 -14.3000 -13.6000 -12.9000 -12.3000 -11.6700 -10.3700 6.0000 -18.0700 -16.9600 -16.4300 -15.9200 -13.9000 -12.8400 -12.3500 -12.1100 NaN 7.0000 NaN -19.8000 -18.2300 -16.9200 -14.5000 -13.1000 -12.8000 -12.2000 -11.2000 8.0000 -23.6000 -21.8900 -19.2000 -15.8000 -13.6000 -12.6000 -12.3000 -12.2000 NaN 9.0000 NaN -24.6100 -22.2400 -18.4900 -15.0200 -13.2500 -12.4500 -12.5000 -12.1000 10.0000 -26.2000 -26.0000 -23.9000 -18.2000 -14.0500 -12.7000 -12.7000 -12.9000 NaN
figure
surfc(A1(:,2:end))
colormap(turbo)
xlabel('X')
ylabel('Y')
An alternative approach would be to create ‘x’ and ‘y’ vectors or lengths 17 and 9 and then use that with meshgrid or ndgrid to create (17x9) matrices to use with the scatteredInterpolant function.and the last 9 columns of the matrix (all reshaped to produce column vectors) to create an interpolated matrix.
.

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!