MATLAB giving error while trying to create a 3D scatter plot: Error using sparse (Index exceeds array bounds)
8 views (last 30 days)
hello_world on 17 Jul 2018
I was following the MathWorks example: https://www.mathworks.com/help/stats/tsne.html#bvkcm24-1 which works fine for fisheriris dataset.
[Y2,loss2] = tsne(meas,'Algorithm','exact','NumDimensions',3);
v = double(categorical(species));
c = full(sparse(1:numel(v),v,ones(size(v)),numel(v),3));
However, when I change a dataset to something else, it gives error:
Error using sparse
Index exceeds array bounds.
I have the following:
c = full(sparse(1:numel(v), v, ones(size(v)), numel(v), 3));
where numel(v) = 9339, size(v) = 9339 x 1 double
Here the last argument is digit '3' which I followed from MathWorks example in link above. I want to reduce it to 3 dimensions and create a 3D plot same as in that example.
In my case v has 25 classes unlike 3 in Mathworks exaple. So I changed it as follows:
c = full(sparse(1:numel(v), v, ones(size(v)), numel(v), 25));
This time there is no error in c, but I get the error below:
Error using scatter3 (line 109)
C must be a single color, a vector the same length as X, or an M-by-3 matrix.