# 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-0.

2 views (last 30 days)
Rahul Gulia on 8 Sep 2020
Commented: Rahul Gulia on 9 Sep 2020
This is what i am trying to solve.
>> d = 1 2 3 4 5 6 7 8 9 10
>> dref = 3 5 7
>> A = % Creating from d of size (10x10) using (A = repmat(d, length(d),1))
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
>> B = % Taking only the lower traingle values from the diagonal.
1 0 0 0 0 0 0 0 0 0
1 2 0 0 0 0 0 0 0 0
1 2 3 0 0 0 0 0 0 0
1 2 3 4 0 0 0 0 0 0
1 2 3 4 5 0 0 0 0 0
1 2 3 4 5 6 0 0 0 0
1 2 3 4 5 6 7 0 0 0
1 2 3 4 5 6 7 8 0 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 10
using this;
B = zeros(length(d),length(d));
for i = 1:length(d)
B(i,1:i) = d(1):d(i);
end
* This is what i have already done. Now i want two matrices out of "B" matrix.
matrix C = containing all the diagonal values of B, and the values of "dref" in each row.
example, C =
1 0 0 0 0 0 0 0 0 0
0 2 0 0 0 0 0 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 3 4 0 0 0 0 0 0
0 0 3 0 5 0 0 0 0 0
0 0 3 0 5 6 0 0 0 0
0 0 3 0 5 0 7 0 0 0
0 0 3 0 5 0 7 8 0 0
0 0 3 0 5 0 7 0 9 0
0 0 3 0 5 0 7 0 0 10
matrix D = containing all the values of matrix B, without the diagonal elements and the "dref" values in each row.
example, D =
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 2 0 0 0 0 0 0 0 0
1 2 0 0 0 0 0 0 0 0
1 2 0 4 0 0 0 0 0 0
1 2 0 4 0 0 0 0 0 0
1 2 0 4 0 6 0 0 0 0
1 2 0 4 0 6 0 0 0 0
1 2 0 4 0 6 0 8 0 0
1 2 0 4 0 6 0 8 9 0
I have tried every method in my mind to solve it. But of no use. Just a hint would also suffice guys.
Rahul Gulia on 9 Sep 2020
I have edited my problem guys, to explain it in a much better way. Hope that helps.

Rik on 9 Sep 2020
This should do the trick:
d = 1:10;
dref = [3 5 7];
A = repmat(d, length(d),1);
B = zeros(length(d),length(d));
for i = 1:length(d)
B(i,1:i) = d(1):d(i);
end
%my code:
d = 1:10;
dref = [3 5 7];
A=repmat(reshape(d,1,[]),numel(d),1);
B=tril(A);
diagonal=B.*(eye(size(B)));
lower_part=B.*(1-eye(size(B)));
L=ismember(lower_part,dref);
lower_part(~L)=0;
C=lower_part+diagonal;
D=B-C;
Rahul Gulia on 9 Sep 2020
That worked. Thank you Rik..