Filling out multiple structures in an if loop

조회 수: 1 (최근 30일)
Tim Johansson
Tim Johansson 2020년 10월 16일
댓글: Ameer Hamza 2020년 10월 19일
Im trying to set up some data to use in machine learning, but i am having a hard time setting up the data.
Right now im trying to sort my data into different structures according to label.
for k = 1:20
if rawData.sub1.run.label{1, 1}.data(k,3) == 0
classData.sub1.right{k}=rawData.sub1.run.epochs.run1.movement{k}
elseif rawData.sub1.run.label{1, 1}.data(k,3) == 1
classData.sub1.up{k}=rawData.sub1.run.epochs.run1.movement{k}
elseif rawData.sub1.run.label{1, 1}.data(k,3) == 2
classData.sub1.left{k}=rawData.sub1.run.epochs.run1.movement{k}
elseif rawData.sub1.run.label{1, 1}.data(k,3) == 3
classData.sub1.down{k}=rawData.sub1.run.epochs.run1.movement{k}
end
end
My problem is the "right{k}" ... down{k} structures.
if i dont input a k, the loop will simply replace the data that is already placed in the structure with the new data that belongs in the scructure.
However if i give the input k, multiple cells inside the structure is left as null, making it hard to call for the data again.
I've been reading up on structures but cant seem to find a simple solution.
i was thinking if it was possible to have a integer that only changed value every forth loop?
Any ideas are appreciated

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 16일
If you want an integer which only increment every fourth iteration then you can use ceil() or floor() functions. For example
for k = 1:20
disp(ceil(k/4))
end
Result
>> for k = 1:20
disp(ceil(k/4))
end
1
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4
5
5
5
5
  댓글 수: 2
Tim Johansson
Tim Johansson 2020년 10월 19일
Thank you very much!
Ameer Hamza
Ameer Hamza 2020년 10월 19일
I am glad to be of help!!!

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

추가 답변 (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