Unable to perform assignment because the left and right sides have a different number of elements, Fisheriris

2 次查看(过去 30 天)
I am trying to implement SVM on my data using Fisheriris example available in this site:
I received the following error for this line of code:
h(1:3) = gscatter(X(:,1),X(:,2),Y);
my X(:,1) is 259200X1 (type double), X(:,2) is 259200X1 (type double) and Y is 259200X1 (type cell), just like the example
an initialization for h is given in the previous line:
h = zeros(3 + L,1); % Preallocate for handles
in the Fisheriris example: L = 3; my L = 28;
I am using that SVM to classify to 8 different classes rather than 3 classes, like in the Fisheriris.
So what can I do to fix the error, thanks in advance.

回答(1 个)

Walter Roberson
Walter Roberson 2019-3-17
gscatter() returns a number of handles equal to the number of groups it detects. Since you appear to have 8 groups, it will probably return 8 handles.
It is not recommended to initialize arrays of handles as numeric in R2014b and later. Use gobjects() instead of zeros()
  3 个评论
Walter Roberson
Walter Roberson 2019-3-17
Using gobjects will not solve the problem, but it might solve later problems.
You need to change the code to allocate 8+L handles instead of 3+L, and you need to change
h(1:3) = gscatter(X(:,1), X(:,2), Y);
to
h(1:8) = gscatter(X(:,1), X(:,2), Y);
I suggest that at the point just before you call gscatter, that you call save() to save your progress, and that you alter your code structure to be able to resume from saved values.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by