Plot 3D surface from Excel .csv File
47 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to plot 3D surface from the attached excel csv file (data.csv).
I want the surface to be smooth if possible.
- x = first column;
- y = second column;
- z = third column.
I am new to Matlab and I have been struggling to do it. Could you please help me?
Also, how could I annotate the minumum of the surface and its x and y coordinates as well.
Thanks a lot!
-
0 个评论
采纳的回答
Simon Chan
2021-8-29
You may extract the data using function readmatrix.
clear; clc;
rawdata = readmatrix('data.csv');
x = reshape(rawdata(:,1),[],51); % Reshape the column matrix into 51 columns
y = reshape(rawdata(:,2),[],51);
z = reshape(rawdata(:,3),[],51);
surf(x,y,z)
result as follows:
7 个评论
Tom
2023-3-1
hi, i'm trying to use this code to create my own contour plot from a csv file that has data in a 3x55 matrix.
is there any reason you converted the column matrix into specifically a 51 column matrix?
and how would i need to adapt this code to use with my csv file?
sorry, i am also very new to matlab but it's the only software i have access to that does what i need for a final year project.
thanks, t
Simon Chan
2023-3-2
You may spend some time to look at the attached csv file.
Actually there are totally 51x51 data but arranged in a column vector. On the other hand, function surf requires z-coordinates to be a matrix. So the conversion mainly converts the z-coordinates, which is the third column in this csv file into a matrix.
While for the x and y coordinates, they are both going from 0 to 0.5 with step size 0.01, and hence there are totally 51 data points. Without extracting the x and y-coordinates from the csv file, you may also use the following line to do the same thing.
[x,y] = meshgrid(0:0.01:0.5); % 2D grid for both 0:0.05:0.5
z = reshape(rawdata(:,3),length(0:0.01:0.5),length(0:0.01:0.5)); % Reshape z into a 51x51 matrix
surf(x,y,z);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!