how to plot using surf function?

5 ビュー (過去 30 日間)
Muazma Ali
Muazma Ali 2022 年 7 月 31 日
編集済み: dpb 2022 年 7 月 31 日
Hi
I am using this code as attached in my file and I am struggling with getting markers as circles; I dont find anything on properties tool that I can change to get markers as circles and not a line.
test %Matt J inserted so we can see result of running the attachment
Unrecognized function or variable 'X'.

Error in test (line 7)
surf(X, Y, Z, Z )
  1 件のコメント
Matt J
Matt J 2022 年 7 月 31 日
Your attached code doesn't generate anything currently, as the Run ouput that I inserted for you demonstrates.

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

回答 (2 件)

David Hill
David Hill 2022 年 7 月 31 日
You only have 3 points. z would need to be a matrix to use surf.
osmotisk_data = readtable("tester_tabeller.xlsx");
x = osmotisk_data{:,3};
y = osmotisk_data{:,1};
z = osmotisk_data{:,2};
plot3(x,y,z)
  2 件のコメント
Muazma Ali
Muazma Ali 2022 年 7 月 31 日
@David Hill cant Z be only a single column matrix then...?
I get this picture as attached when I run the code.
dpb
dpb 2022 年 7 月 31 日
編集済み: dpb 2022 年 7 月 31 日
Not from that m-file and data, not possible.
>> type test.m
osmotisk_data = readtable("tester_tabeller.xlsx");
x = osmotisk_data{:,3};
y = osmotisk_data{:,1};
z = osmotisk_data{:,2};
surf(X, Y, Z, Z )
colorbar
% grid on
>> test
Unrecognized function or variable 'X'.
Error in test (line 7)
surf(X, Y, Z, Z )
>>
As the comment in Answer below noted, the surf command uses uppercase variable names instead of the defined lowercase ones used in extracting the data from the table.
There's the problem in using scripts -- there must be some OTHER set of X,Y,Z in your workspace different than the x,y,z you just defined from the read data file.
If then use the actual variable names instead, then
>> surf(X, Y, Z, Z )
Unrecognized function or variable 'X'.
Did you mean:
>> surf(x, y, z, z )
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
>>
which is @David Hill's point -- and "No, you canNOT have only a vector for surf; you've got to have a full 2D array of a value for every x,y pair -- in this case that would require a 3x3 array since there are three values for each x and y.

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


dpb
dpb 2022 年 7 月 31 日
編集済み: dpb 2022 年 7 月 31 日
osmotisk_data = readtable("tester_tabeller.xlsx");
x = osmotisk_data{:,3};
y = osmotisk_data{:,1};
z = osmotisk_data{:,2};
surf(X, Y, Z, Z )
I don't know what else one would expect from such code??? Tries to plot uppercase variables but defined lowercase ones instead.
And, there's nothing in call to surf that will set the marker style to anything but the default which by the documentation is 'none' and to set/turn the linestyle off.
surf(x,y,z,'linestyle','none','marker','o')
  1 件のコメント
dpb
dpb 2022 年 7 月 31 日
Of course, the above assumes the data are commensurate with the need to have a 2D array for Z which isn't so (and can't be so out of a table as constructed; one would have to build the 2D array to match.

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

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by