Table in a for loop

조회 수: 3 (최근 30일)
Mads Kattrup Pedersen
Mads Kattrup Pedersen 2021년 5월 3일
댓글: Mads Kattrup Pedersen 2021년 5월 3일
Hello, im having trouble figuring out how to make a table inside my for loop.
Im currently using disp and i would like to "print" it to a table instead. Preferably leftFootContact. The table would be roughly 1186 rows in 1 column.
datalength = length(tree.footContact(1).footContacts);
leftFootContact = [];
for ii=1:datalength
if tree.footContact(1).footContacts(ii,1) == 0 && tree.footContact(2).footContacts(ii,1) == 0
disp('0')
else
disp('1')
end
end
  댓글 수: 2
Adam Danz
Adam Danz 2021년 5월 3일
It's not clear what you'd like to display. '0' and '1' are single characters. How should be be displayed as tables?
Mads Kattrup Pedersen
Mads Kattrup Pedersen 2021년 5월 3일
Both "tree.footContact(1).footContacts(ii,1)" and "tree.footContact(2).footContacts(ii,1)" are 1186x1 doubles filled with 0s and 1s.
And right now it just displays the 0s and 1s in the command window, and i would like for it to save it into a new 1186x1 double, i guess. I dont know if that makes sense, im rather confused at this point.

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

채택된 답변

Adam Danz
Adam Danz 2021년 5월 3일
편집: Adam Danz 2021년 5월 3일
Assuming those values are boolean,
z = ~(~tree.footContact(1).footContacts(:,1) & ~tree.footContact(2).footContacts(:,1));
  댓글 수: 1
Mads Kattrup Pedersen
Mads Kattrup Pedersen 2021년 5월 3일
This seems to be working. Thanks alot!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by