Filling out multiple structures in an if loop

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Ameer Hamza
Ameer Hamza il 16 Ott 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by