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);

采纳的回答

Jan
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.
  1 个评论
L. E.
L. E. 2017-3-25
Thanks! I was able to get it going after this. It is a pretty strange set of code - the intention is to model water chemistry mixing and source water in a stream.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by