## Matrix element changing with loop

Hans123

### Hans123 (view profile)

님이 질문을 제출함. 16 Feb 2019
최근 활동 Stephen Cobeldick

### Stephen Cobeldick (view profile)

님이 편집함. 17 Feb 2019
Stephen Cobeldick

### Stephen Cobeldick (view profile)

님이 답변을 채택함.
I keep getting Dimensions of matrices being concatenated are not consistent error.
for k=1:61
a(:,k)=angle(k,:);
A=[cosd(5) -sind(a); -sind(5) cosd(a)];
x=A\B;
end
I don't get what I am doing wrong

16 Feb 2019
a(k,:)

로그인 to comment.

## 답변 수: 1

### Stephen Cobeldick (view profile)

Stephen Cobeldick

### Stephen Cobeldick (view profile)

님의 답변 16 Feb 2019
Stephen Cobeldick

### Stephen Cobeldick (view profile)

님이 편집함. 16 Feb 2019
채택된 답변

5 is a scalar. A scalar has size 1x1.
On the second loop iteration a has size Nx2 (we don't know the actual size because you did explain what size angle is).
Then you calculate some trig functions using those 5 and a, giving 1x1 and Nx2 arrays. You then try to concatenate those arrays like this:
[1x1,Nx2;1x1,Nx2]
which is an error if N>1 because then the number of rows are different, which means that those arrays cannot be concatenated together horizontally:
• To horizontally concatenate arrays they must have the same number of rows.
• To vertically concatenate arrays they must have the same number of columns.
Check the sizes of the arrays that you are trying to concatenate and you will find that one/both of those conditions are not fulfilled.

Hans123

### Hans123 (view profile)

16 Feb 2019
I am not 100% sure on how to correct the issue, I just need the matrix to have different values for angle after each iteration how to achieve this? I pasted the code below
angle=-30:1:30;
B= [1200 ; 0 ];
for k=1:61
a(:,k)=angle(k,:);
A=[cosd(5) -sind(a); -sind(5) cosd(a)];
x=A\B;
end
Stephen Cobeldick

### Stephen Cobeldick (view profile)

17 Feb 2019
This avoids the error:
a = angle(k);
Only you can decide if this is correct or not.
Also note that you completely discard all x arrays except fot the last one, making your entire for loop superfluous. You might want to use some indexing into an output array.

로그인 to comment.

Translated by