Error using horzcat Dimensions of arrays being concatenated are not consistent?

조회 수: 5 (최근 30일)
hello. i solve some differential equation with ode45. The answers are correct and there is no error.because i want to show some variables that are not in diffrential equation i use the command:
[dx phee] =melanie_ode_fj(t,Y)
but there is this error:
Error using horzcathorzcat
Dimensions of arrays being concatenated are not consistent.
i do not know why ? the codes run correctly and there is no error.
codes are long so i attach them.
you should run MAIN.
Thanks
  댓글 수: 2
Jan
Jan 2019년 1월 14일
편집: Guillaume 2019년 1월 14일
Please post the complete error message. Where does the problem occur?
Users, who try to help you, might loose their current work by your evil clear all. Use functions to keep your workspace clean instead of a brutal clearing, which wastes a lot of time.
Najmeh Eskandari
Najmeh Eskandari 2019년 1월 14일
this is complete error message:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in melanie_ode_fj (line 14)
c_m=[.635 .3133 -4+t]';
c_m is a vector (3 by 1) and it is correct.
if the error relates to dimension of dx or phee?
after running codes and ode i use that command (previous post) in command window to get phee and plot it.
the value of phee changes with time and is defined in "corrective control.m".

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2019년 1월 14일
Your ‘melanie_ode_fj’ function has only one output (as it should):
function dx=melanie_ode_fj(t,x)
If you want other outputs from it, create a second version of it (with a slightly different name, I call it ‘melanie_ode_fj_more_outputs’ here) with the outputs you want.
Then, use a for loop and the results of the original ‘melanie_ode_fj’ integration to get the other information you want.
For example (assuming your time vector is ‘t’):
for k = 1: numel(t)
[dx{k} phee{k}] = melanie_ode_fj_more_outputs(t(k),Y(k));
end
NOTE: This is UNTESTED CODE and is for illustration purposes only!
  댓글 수: 3
Star Strider
Star Strider 2019년 1월 14일
Because the ODE function has only one output, as it should. To return more variables without significantly complicating the ODE solver call, a second function that creates and returns the necessary variables is the easiest solution.
Stephen23
Stephen23 2019년 5월 27일
One nargout would be simpler, rather than duplicating an entire function.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by