Getting subscripted assignment dimension mismatch error?
조회 수: 1 (최근 30일)
이전 댓글 표시
I am getting a subscripted assignment dimension error for the bit of code I have attached. I'm not sure what this means or how to fix it. Thank you for your help!
Full error message:
Subscripted assignment dimension mismatch.
Error in EMMA_GL4 (line 62) f(:,j)=B' * U_f(:,j);
댓글 수: 0
채택된 답변
Jan
2017년 3월 25일
B = [U_GL4_Baseflow(1,1),U_GL4_Tallus0(1,1),U_GL4_snowmelt(1,1); ...
U_GL4_Baseflow(1,2),U_GL4_Tallus0(1,2),U_GL4_snowmelt(1,2)];
X = ('U_GL4_Strm');
Now I guess that B is a [2 x 3] double matrix and X is a string.
X_size = size(X, 2);
mat_1 = ones(1, X_size);
U_f = [mat_1; X];
U_f consists of the unprintable character with teh ascii code 1's in the first row and the characters of the string 'U_GL4_Strm' in the 2nd row:
U_GL4_Strm
This is strange and I have no idea what the intention for this might be. Now the failing line:
f(:,j) = B' * U_f(:,j);
On the right side the [3 x 2] double matrix B' is multiplied by a [2 x 10] char matrix, which yields a [3 x 1] vector in the first iteration. If f is undefined before, this works. If you get an error, the variable f was defined before and its number of columns differs from 3.
Solution: Do not define f before. A good idea is to use a function to keep the workspace clean. Or pre-allocate f correctly:
i = 16;
f = zeros(3, i);
for j=1:i
f(:,j) = B' * U_f(:,j);
end
Then the next problem will occur: U_f has 10 columns only, not 16.
Anyway, the strange mixture of numerical values and the string might be the main problem.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!