How to correct this error?"Subscripted assignment dimension mismatch."
Show older comments
Hi, I would like to create a column vector which is called ub with for loop but I got this error: Subscripted assignment dimension mismatch.
Error in Test_WSVM (line 74) ub(i,1)= C*(7/15)*ones(n,1); » Here is my code
if true
clc;clear;close all;
%Load Data
load Unblanced_Data.mat
x = unblanced_data;
%%Data Normalaization
m=size(x,1);
xMean = repmat(mean(x),m,1);
xStd = repmat(std(x),m,1);
x_norm = (x - xMean)./(xStd);
%%Training SVM
x_1=[x_norm(1:6400,:); x_norm(8001:13600,:)];
y_1=[-ones(6400,1);ones(5600,1) ];
TrainInputs = (x_1)';
TrainTargets =(y_1)';
ClassFault = find(TrainTargets == 1);
ClassNormal = find(TrainTargets == -1);
n=numel(TrainTargets);
%% Design SVM
C=10;
sigma=1.5;
Kernel=@(xi,xj) exp(-1/(2*sigma^2)*norm(xi-xj)^2);
H=zeros(n,n);
for i=1:n
for j=i:n
H(i,j)=TrainTargets(i)*TrainTargets(j)*Kernel(TrainInputs(:,i),TrainInputs(:,j));
H(j,i)=H(i,j);
end
end
f=-ones(n,1);
Aeq=(y_1)';
beq=0;
lb=zeros(n,1);
ub = zeros(n,1);
for i=1:n
if (TrainTargets(1,i) == 1)
ub(i,1)= C*(8/15)*ones(n,1);
else
ub(i,1)= C*(7/15)*ones(n,1);
end
end
options = optimset('Algorithm', 'interior-point-convex','Display',...
'off','MaxIter',20);
alpha=quadprog(H,f,[],[],Aeq,beq,lb,ub,[],options)';
end
Any helps would be appreciated.
Accepted Answer
More Answers (0)
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!