How to plot a table in a way that first column and first raw are x and y axis?

27 ビュー (過去 30 日間)
Masoud Taleb
Masoud Taleb 2020 年 5 月 1 日
編集済み: dpb 2020 年 5 月 1 日
Hello
I have a table of data in csv format (shown below) and want to plot them in Matlab using surf function. First column and first row are the x and y axis. Middel onse are collected data. It seems reading raw is a problem in Matlab. Can anyone suggest an easy way to plot such a table? All my tries failed :(
my data look like this in csv file:
0 100 200 300 400
330 53 45 76 22
340 21 34 32 87
A = readmatrix ('Y1.csv');
x = A(:,1) ;
y = A(1,:) ;
z = A(2:end,2:end) ;
z = transpose(z)
surf (x, y, z)
shading interp

採用された回答

dpb
dpb 2020 年 5 月 1 日
There is no data for the (0,0) coordinate so it can't be in the X,Y vectors---and the Z array must be size(Z)-->[m,n] where X,Y correspond to [m,n]. IOW, you don't transpose...
x = A(2:end,1); % don't include origin; no data point available
y = A(1,2:end); % ditto
z = A(2:end,2:end) ;
surf (x, y, z)
  2 件のコメント
Masoud Taleb
Masoud Taleb 2020 年 5 月 1 日
Thank you very much. I got the point. Your written code worked after I added transpose to it. So, everything is fine now :)
dpb
dpb 2020 年 5 月 1 日
編集済み: dpb 2020 年 5 月 1 日
"Your written code worked after I added transpose "
My code works as written; I see you used the alternate for X and Y than I did...I thought I pulled that from your original posted code, too, but apparently not.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by