Filling out multiple structures in an if loop

1 次查看(过去 30 天)
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

更多回答(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