필터 지우기
필터 지우기

save data in for loops

조회 수: 2 (최근 30일)
yunwei hu
yunwei hu 2020년 2월 10일
편집: Ajay Kumar 2020년 2월 11일
Hi everyone,
I am trying to save my data into a matrix, each time two columns as X and Y.
but the codes don't work.
Can anyone explain and help?
Thanks a lot.
coordinate= zeros();
for a=1:21
Z=[X Y];
X = snakes{1,a}.x;
Y = snakes{1,a}.y;
coordinate((a),:)= Z;
end
  댓글 수: 4
Ajay Kumar
Ajay Kumar 2020년 2월 10일
what is the format of those?
Could you upload x, y and snakes here.
yunwei hu
yunwei hu 2020년 2월 10일
i uploaded the snakes.
x and y are all inside of it.

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

채택된 답변

Ajay Kumar
Ajay Kumar 2020년 2월 11일
편집: Ajay Kumar 2020년 2월 11일
Yes, You are trying to assign 2 matrices of different size. Try this:
coordinate= zeros(41,1);
for a=1:21
X = snakes{1,a}.x;
Y = snakes{1,a}.y;
% Z=[X Y];
if a == 1
coordinate(:,end)= X;
coordinate(:,end+1) = Y;
else
coordinate(:,end+1)= X;
coordinate(:,end+1) = Y;
end
end
coordinate size will be 41x42. For each a, we have 41x2 which means for 21 a's it will be 41x42.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by