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

2 ビュー (過去 30 日間)
Achawi Salma
Achawi Salma 2020 年 4 月 14 日
回答済み: Vinai Datta Thatiparthi 2020 年 4 月 25 日
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).

回答 (1 件)

Vinai Datta Thatiparthi
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!

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by