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

조회 수: 1(최근 30일)
Usman Bashir Tayab 2023년 1월 24일
답변: the cyclist 2023년 1월 24일
I am getting following error. Anyone can help me to solve it
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-120.
n=20;
for i = 1:n
D(i,:) = min(X(i,:)) + max(X(i,:)) - X(i,:);
end

댓글을 달려면 로그인하십시오.

### 답변(1개)

the cyclist 2023년 1월 24일
You haven't quite given us enough information about your code, because that little code snippet may or may not work, depending on what D looks like before the loop. In the code below, I show three possible examples of D. The first two work, and the third one does not. I expect your full code defines D to be the wrong size going into the loop.
rng default
X = rand(120,120);
% D is not yet defined
disp("D not defined")
D not defined
n=20;
for i = 1:n
D(i,:) = min(X(i,:)) + max(X(i,:)) - X(i,:);
end
% An example of D that works
D = rand(1,120);
disp("D is 1x30")
D is 1x30
n=20;
for i = 1:n
D(i,:) = min(X(i,:)) + max(X(i,:)) - X(i,:);
end
% An example of D that does not work
D = rand(1,1);
disp("D is 1x1")
D is 1x1
n=20;
for i = 1:n
D(i,:) = min(X(i,:)) + max(X(i,:)) - X(i,:);
end
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-120.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Data Type Identification in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by