Subscripted assignment dimension mismatch
이전 댓글 표시
Below is my code. When my program tries to calculate D, it gives me the error as stated in the title. the Varibles N, Eab, den, and V all produce a matrix of 1x47 values. I have tried removing the dot (.) from the equation's multiplication and divisons, but I still get errors (inner matrix dimnesions must agree). Any help is appreciated. Thank you.
row = 0;
col = 0;
for row = 1:1:420
for col = 1:1:420
N = No - No.*exp(-linavg*d);
Eab = E.*(lin./linavg);
D(row,col) = (N.*Eab)./(den.*V);
No = N*exp(-linavg*d);
end
col = col +1;
end
row = row+ 1;
댓글 수: 3
per isakson
2020년 3월 4일
편집: per isakson
2020년 3월 4일
What are the statemets
row = 0;
col = 0;
col = col +1;
row = row+ 1;
supposed to do?
Pre-allocate D before entering the for-loops
D = nan(420,420);
Left hand side of
D(row,col) = (N.*Eab)./(den.*V);
is a scalar and the right hand side is a 1x47 vector. That doesn't agree. What do you want to achieve with this statement?
Kira Bruce
2020년 3월 4일
Aquatris
2020년 3월 4일
편집: per isakson
2020년 3월 4일
First of you do not need to specify col = col+1. When you define for col = 1:100, the for loop will increment the col variable every iteration
Secondly, do you want D to be a 3D matrix? If so,
D(row,col,1:47) = (N.*Eab)./(den.*V);
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!