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.

1 回表示 (過去 30 日間)
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.
Thanks in advance.
  4 件のコメント
Walter Roberson
Walter Roberson 2020 年 9 月 8 日
Look at your first value in dlink, which is 0. You intersect(0, dref) where dref is [7 3 6 6]. The intersection of those two sets is empty. You try to assign that emptiness to the definite location A(ii,p) . That is a mismatch on sizes, no values to assign but has to go into a place that has holds exactly one value.
I am trying to find the dref values in each outer loop
I do not understand that?
Are you trying to find the dlink values that are members of dref? If so then without loops,
intersect(dlink, dref)
which would give you [3 5 7]. That would not appear to be useful, as it is going to be the same as unique(dref)
Rahul Gulia
Rahul Gulia 2020 年 9 月 9 日
I have edited my problem guys, to explain it in a much better way. Hope that helps.

サインインしてコメントする。

採用された回答

Rik
Rik 2020 年 9 月 9 日
This should do the trick:
%your inital code:
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;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by