Is it possible to plot a 3D graph with non numerical values?

9 ビュー (過去 30 日間)
Navya Mohan
Navya Mohan 2019 年 10 月 29 日
回答済み: Navya Mohan 2019 年 10 月 30 日
I have a set of values for plotting like
z= {66%,77,78,79,79}
y= {25%,44,67,34,55}
x= { Class1, Class2, Class3, Class4,Class5}
How to plot a 3d graph with with non numeric values like x(along any one axis) in 3D graph? plz help !

回答 (3 件)

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 10 月 29 日
The simplest method might be to map your classes to some integer range and then use the standard plotting functions. In your case you could try:
z = [66,77,78,79,79]; % use cell2mat to do this for larger arrays
y = [25,44,67,34,55];
x = {Class1, Class2, Class3, Class4,Class5}
X = [1,2,3,4,5]
xstr = unique({'Class1', 'Class2', 'Class3', 'Class4','Class5'});
scatter3(X,y,z,32,X,'filled')
set(gca,'xtick',X,'xticklabel',xstr)
HTH

Walter Roberson
Walter Roberson 2019 年 10 月 29 日
編集済み: Walter Roberson 2019 年 10 月 29 日
z = [66,77,78,79,79];
y = [25,44,67,34,55];
x = categorical({'Class1', 'Class2', 'Class3', 'Class4', 'Class5'});
pointsize = 32;
scatter3(x, y, z, pointsize, x); %color by category
  1 件のコメント
Bjorn Gustavsson
Bjorn Gustavsson 2019 年 10 月 29 日
For my old version of matlab, it was not allowed to create a categorical array, but the same result could be achieved with:
x = ordinal({'Class1', 'Class2', 'Class3', 'Class4', 'Class5'});

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


Navya Mohan
Navya Mohan 2019 年 10 月 30 日
Thank you all! found the codes useful!

Community Treasure Hunt

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

Start Hunting!

Translated by