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

1 回表示 (過去 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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by