Im running a simulation in Simscape Multibody that is outputting the velocities in a 199x1 double (called velocity). Im then changin one of the variables 25 times, in a loop and i want to get a big matrix at the end that will output all of the velocites in one place. This is my current code:
%% landing velocity
%initialise matrix
landing_velcity=[];
for i = 1:25
c=9200;
M=300+(100*i);
system=sim ('dropping.slx');
landing_velocity(i)=velocity
end
The error I'm getting is that the left and right sides have different elements.

답변 (1개)

Adam Danz
Adam Danz 2020년 4월 13일
편집: Adam Danz 2020년 4월 14일

0 개 추천

Pre-allocate your loop variable according to the number of loops and the length of the variable being stored. Here's an example.
landing_velocity = nan(25, numel(velocity)); % updated to fix typos
for i = 1:25
. . .
landing_velocity(i,:)=velocity;
end

댓글 수: 2

landing_velocity = nan(25, numel(velocity)); % 2 corrections
Adam Danz
Adam Danz 2020년 4월 14일
Good catch.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 4월 13일

댓글:

2020년 4월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by