Unable to perform assignment because the size of the left side is 7-by-1 and the size of the right side is 7-by-7

2 Ansichten (letzte 30 Tage)
Hi, I would like to pass some extra arguments to my ODE as follows:
[T,H] = ode23t(@(t,h) MYODE(t,h,G,N,e,n,z,initialnode,w,Qcell,lambda), tspan, h0, opts);
[~,Qcell] = cellfun(@(t,h) MYODE(t,h,G,N,e,n,z,initialnode,w,Qcell,lambda), num2cell(T), num2cell(H,2), 'uni',0);
but I get this error:
Unable to perform assignment because the size of the left side is 7-by-1 and the size of the right side is 7-by-7.
Any idea on how to fix it?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 11 Jul. 2020
The boundary conditions, h, will always be passed to the function as a column vector even if you initialize as a row vector. Your extra arguments have at least one row vector that you are combining elementwise with h thinking that h is a row vector. But because it is a column vector you are getting implicit expansion, as if you had used bsxfun.
Review your code and ensure that you have the right orientation for all your inputs taking into consideration that h will be received as a column vector.
  2 Kommentare
Sim
Sim am 11 Jul. 2020
Thanks a lot Walter!!
I checked the code and I got the line which caused the error (it was inside my ODE function)
% The last column of A was updated with h at each ODE iteration
B(:,3) = A(:,3) + h
Here an example about A, B and h
% Example of one iteration of ODE
A =
0 100 17
250 100 15
500 100 12
750 0 9
750 200 9
900 0 18
900 200 18
h =
0.0080701
0.0019583
0.11659
3.1164
3.1164
0.001
0.001
B =
0 100 17.008
250 100 15.002
500 100 12.117
750 0 12.116
750 200 12.116
900 0 18.001
900 200 18.001
I do not know why (?), but at the last iteration h was a row and not a column as usually defined and as correctly outputed during all the previous ODE iterations.
Neverthenless, I worked around it in this way
if isrow(h); h = h'; end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by