how to plot using surf function?

5 views (last 30 days)
Muazma Ali
Muazma Ali on 31 Jul 2022
Edited: dpb on 31 Jul 2022
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 Comment
Matt J
Matt J on 31 Jul 2022
Your attached code doesn't generate anything currently, as the Run ouput that I inserted for you demonstrates.

Sign in to comment.

Answers (2)

David Hill
David Hill on 31 Jul 2022
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 Comments
Muazma Ali
Muazma Ali on 31 Jul 2022
@David Hill cant Z be only a single column matrix then...?
I get this picture as attached when I run the code.
dpb
dpb on 31 Jul 2022
Edited: dpb on 31 Jul 2022
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.

Sign in to comment.


dpb
dpb on 31 Jul 2022
Edited: dpb on 31 Jul 2022
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 Comment
dpb
dpb on 31 Jul 2022
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.

Sign in to comment.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!