Filling out multiple structures in an if loop

1 vue (au cours des 30 derniers jours)
Tim Johansson
Tim Johansson le 16 Oct 2020
Commenté : Ameer Hamza le 19 Oct 2020
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

Réponse acceptée

Ameer Hamza
Ameer Hamza le 16 Oct 2020
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 commentaires
Tim Johansson
Tim Johansson le 19 Oct 2020
Thank you very much!
Ameer Hamza
Ameer Hamza le 19 Oct 2020
I am glad to be of help!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by