MATLAB Answers

0

Expression or statement is incorrect--possibly unbalanced (, {, or [.

Asked by ghali ahmed on 10 Nov 2017
Latest activity Commented on by Walter Roberson
on 11 Nov 2017
hello every body i have an error ??? Error: File: test.m Line: 31 Column: 3 exactely in [~,scores] = predict(cl,xGrid); i have Matlab 7.8.0 (R2009a)
  1. rand(1); % For reproducibility
  2. r = sqrt(rand(100,1)); % Radius
  3. t = 2*pi*rand(100,1); % Angle
  4. data1 = [r.*cos(t), r.*sin(t)]; % Points
  5. r2 = sqrt(3*rand(100,1)+1); % Radius
  6. t2 = 2*pi*rand(100,1); % Angle
  7. data2 = [r2.*cos(t2), r2.*sin(t2)]; % points
  8. figure;
  9. plot(data1(:,1),data1(:,2),'r.','MarkerSize',15)
  10. hold on
  11. plot(data2(:,1),data2(:,2),'b.','MarkerSize',15)
  12. ezpolar(@(x)1);ezpolar(@(x)2);
  13. axis equal
  14. hold off
  15. data3 = [data1;data2];
  16. theclass = ones(200,1);
  17. theclass(1:100) = -1;
  18. %Train the SVM Classifier
  19. cl = fitcsvm(data3,theclass,'KernelFunction','rbf',...
  20. 'BoxConstraint',Inf,'ClassNames',[-1,1]);
  21. % Predict scores over the grid
  22. d = 0.02;
  23. [x1Grid,x2Grid] = meshgrid(min(data3(:,1)):d:max(data3(:,1)),...
  24. min(data3(:,2)):d:max(data3(:,2)));
  25. xGrid = [x1Grid(:),x2Grid(:)];
  26. [~,scores] = predict(cl,xGrid);
  27. % Plot the data and the decision boundary
  28. figure;
  29. h(1:2) = gscatter(data3(:,1),data3(:,2),theclass,'rb','.');
  30. hold on
  31. ezpolar(@(x)1);
  32. h(3) = plot(data3(cl.IsSupportVector,1),data3(cl.IsSupportVector,2),'ko');
  33. contour(x1Grid,x2Grid,reshape(scores(:,2),size(x1Grid)),[0 0],'k');
  34. legend(h,{'-1','+1','Support Vectors'});
  35. axis equal
  36. hold off

  1 Comment

It is working pretty fine in 2017.

Sign in to comment.

Tags

Products

1 Answer

Answer by Steven Lord
on 10 Nov 2017

The ability to ignore specific input or output arguments in function calls using the tilde operator was introduced in release R2009b. Replace ~ with a dummy variable name, like dummy, for older releases.

  3 Comments

i'll to thank you for quick response
i have an other problem
??? Undefined function or method 'fitcsvm' for input arguments of type 'double'.
Error in ==> test at 23
cl = fitcsvm(data3,theclass,'KernelFunction','rbf',...
fitcsvm - Train binary support vector machine classifier
fitcsvm trains or cross-validates a support vector machine (SVM)
model for two-class (binary) classification on a low- through
moderate-dimensional predictor data set. fitcsvm supports...
Documentation > Statistics and Machine Learning Toolbox > Classification > Support Vector Machine Classification
That routine was introduced in R2014a.
In your software release there was no built-in SVM in any toolbox, so people would compile and link the third party libsvm

Sign in to comment.