Plot 3D surface from Excel .csv File

56 ビュー (過去 30 日間)
HAMID
HAMID 2021 年 8 月 29 日
コメント済み: Simon Chan 2023 年 3 月 2 日
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!
-

採用された回答

Simon Chan
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
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
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 ExchangeSpreadsheets についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by