How to correct this error?"Subscripted assignment dimension mismatch."

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.

 采纳的回答

ub(i,1) is a scalar element, but ones(n,1) is a vector if n>1. You can't assign a vector to a scalar element.

1 个评论

Thanks Mr James Tursa for your reply. n =12000 and TrainTargets is a row vector (1*12000). I tried ub(i,:) but I had this error again . I would like to have ub vector after for loop and vector size should be 12000*1 . Would you please guide me to correct my mistakes?

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by