MATLAB: Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-10.

1 by 11 by 10matrixsize;

I have this problem with a code: Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-10.
aThis is my code. How can solve the problem??
What i need to do is to multiply each number of the column vector S1 by an specif row on the P matrix, the number of this row should come from the if. By doing this porcess for all my elements on S1 i should have as result a Matrix of dimension (J1,10), because i have J1 observations and P is 10×10. After hisfor each row of my new matrix i should calculate the mean and finally obtain a column vector. All this porcess is to distort the value of S1 by the matrix P.
S0 = 100;
F0 = 100;
%T = 1;
Q0 = 1;
ERS = 0.05;
ERF = 0;
sigmaS = 0.2;
sigmaF = 0.2;
rhoSF = 0.8;
mu = [ERS, ERF];
sigma = [sigmaS^2, sigmaS * sigmaF * rhoSF; sigmaS * sigmaF * rhoSF, sigmaF^2];
J1 = 5;
r = mvnrnd(mu,sigma,J1);
plot(r(:,1),r(:,2),'o');
S1 = S0 * (1 + r(:,1));
F1 = S0 * (1 + r(:,2));
Y_low = -Q0 * 0.01;
Y_high = -Q0 * 2;
J = 100;
pitch = (Y_high - Y_low)/J;
S1vero = zeros(J1,1);
F1vero = zeros(J1,1);
SP = zeros(J1,10);
maxS1 = max(S1(:,1));
maxF1 = max(F1(:,1));
maxTot= max(maxS1,maxF1);
minS1 = min(S1(:,1));
minF1 = min(F1(:,1));
minTot= min(minS1,minF1);
stepTot_S1=(maxS1 - minS1)/10;
stepTot_F1=(maxF1 - minF1)/10;
intervalsS1 = minS1:stepTot_S1:maxS1;
intervalsF1 = minF1:stepTot_F1:maxF1;
P = [ 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01;
0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02;
0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03;
0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04;
0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05;
0.06 0.06 0.06 0.06 0.06 0.06 0.06 0.06 0.06 0.06;
0.07 0.07 0.07 0.07 0.07 0.07 0.07 0.07 0.07 0.07;
0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08;
0.09 0.09 0.09 0.09 0.09 0.09 0.09 0.09 0.09 0.09;
0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1];
for k = 1:1:J1
for k1 = 1:1:10
if (S1(k,1) >= intervalsS1(1,k1)) && (S1(k,1) <= intervalsS1(1,k1+1))
SP(k,10) = S1(k,1) * P(k1,:);
end
end
end

Best Answer

SP(k,10) = S1(k,1) * P(k1,:);
k is a scalar, so SP(k,1) names a single output location.
k is a scalar, so S1(k,1) names a single input location.
P(k1,:) names a complete column of P, consisting of 10 rows.
Multiplying a scalar S1(k,1) by a column vector 10 x 1, gives a column vector 10 x 1.
So the right hand side has 10 elements, a 10 x 1 result, but the left hand side, SP(k,10) only names a single output location.
I cannot make any recommendations as it is not clear from the comments what the purpose of P is, or what the code is intended to do in those loops.