1
votes

I have a small problem regarding loops with a matlab simple script.

I have a structure/table with for example 13 fields. I want to name differently 3 of those fields for every 6 field. That's example:

  1. qwert
  2. qwert
  3. qwert
  4. something_else
  5. something_else
  6. qwert
  7. qwert
  8. qwert
  9. something_else
  10. something_else
  11. qwert
  12. qwert
  13. qwert ...

That's my code, but it doesn't work well.

v = (1:6:13);
    for i = v:1:3
    table(i).type = 'qwert';
    end

I know that Matlab doesn't want to use this 'v' vector in for loop, instead it wants to have a scalar. How can I solve this?

Thank you very much in advance, Mary

1

1 Answers

0
votes

A simple way:

v = (1:5:13);
for i = v
    for j=0:2
        table(i+j).type = 'qwert';
    end
end

Note that to get your described result, you have to use a steplength of 5... since this is every 5th field, not every 6th.