how to plot using surf function?
5 次查看(过去 30 天)
显示 更早的评论
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
1 个评论
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
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 个评论
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
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
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 Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!