필터 지우기
필터 지우기

Create a loop with condition

조회 수: 1 (최근 30일)
wissal zaher
wissal zaher 2022년 11월 29일
댓글: wissal zaher 2022년 11월 30일
I want to create a loop that generate random intial values x0 as (2,1) vectors within a [-5,5] range.
Each initial value x0 will give out an output U, some values give out U = NaN (calculated with a controller)
I want the loop to keep running for all the values with U not equal NaN and save them in an array Xset
The values with U = NaN can be disqualified
I would appreciate any help

채택된 답변

David Hill
David Hill 2022년 11월 29일
Does not seem like you need random values, but rather all values between -5 to 5
[x,y]=meshgrid(-5:.001:5);%generates all x0 pairs (x;y) within -5 to 5 with .001 step.
i=1;
for k=1:numel(x)
U=%some function with [x(k);y(k)] input
if ~isnan(U)
Xset(:,i)=[x(k);y(k)];
i=i+1;
end
end
  댓글 수: 3
David Hill
David Hill 2022년 11월 29일
[x,y]=meshgrid(-5:.001:5);
xset=[];
for k=1:numel(x)
u = mpc.evaluate([x(k);y(k)]);
if ~any(isnan(u))
xset=[xset,k];
end
end
T_solve=100;
Xset=[];Uset=[];
for k=1:length(xset)
x0=[x(xset(k));y(xset(k))];
for kk=1:T_solve
u = mpc.evaluate(x0);
x1=A*x0+B*u(1);
x0=x1;
Xset=[Xset x0];
Uset=[Uset u];
end
end
wissal zaher
wissal zaher 2022년 11월 30일
thank you a lot !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by