How can I scatter3 with 1 qualitative variable and 2 quantitaive variable ?

2 visualizaciones (últimos 30 días)
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).

Respuestas (1)

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi el 25 de Abr. de 2020
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!

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by