How can I scatter3 with 1 qualitative variable and 2 quantitaive variable ?
2 次查看(过去 30 天)
显示 更早的评论
Hello to all !
I'm new at Matlab and bad at coding, and I need to plot a 3-axis graph. I actually have 3 excel tables that I need to arrange in 3D plot.
So far, I managed to create a 3D plot by replacing my qualitative variable by a quantitative variable, and it works. Here's my code and my plot:
data=importdata("essaidata1.xlsx")
x=data(:,1);
y=data(:,2);
z=data(:,3);
scatter3(x,y,z,'*','g')
xlabel('Taille Latérale (nm)');
ylabel('Epaisseur');
zlabel('C/O ratio');
hold("on");
data=importdata("essaidata2.xlsx")
x=data(:,1);
y=data(:,2);
z=data(:,3);
scatter3(x,y,z,'*','c')
hold("off");
hold("on");
data=importdata("Essaidata3.xlsx")
x=data(:,1);
y=data(:,2);
z=data(:,3);
scatter3(x,y,z,'*','r')
hold("off");
What I would like to do is replacing my C:O ratio (my Z axis) by a class. Instead of a ratio , I would have different class on matarials "material 1", "materail 2", "material 3" . When I try to replace the numbers by the material type directly in my exce data, I have this error :
data =
data: [6×2 double]
textdata: {6×1 cell}
rowheaders: {6×1 cell}
Index in position 2 exceeds array bounds (must not exceed 1).
0 个评论
回答(1 个)
Vinai Datta Thatiparthi
2020-4-25
Hey Achawi,
If you navigate to scatter3 function's documentation about input vectors (LINK), you'll notice that 'char' datatype is not allowed. That is why when you try to replace the numbers by the material type, an error is thrown.
As an alternative, I suggest using the function gscatter. You can group all the values by material number in this case. For this, you may accumulate all your data into a single matrix to begin with.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!