Search code examples
matlabmatlab-figure

Uneven looping and iteration in Matlab


I am a beginner in MATLAB and I am encountering the following problem. I am trying to write a code that will run the x first then after each 4 runs, k increments by 1. I have searched for the solution, but could not find one.

a=[1;2;3;4];
b=[8;4;6;7];
k=[7;4;5;6;7;8;9];
for i = 1:1:4
    for j = 1:1:7
       m=a[i]+ b[i]*k[j]
    end
end

my equation is M=a(x)+b(x)*k(t) where x=1:4 and t=1:7

Like :

1+8*7

2+4*7

3+6*7

4+7*7

Then

1+8*4

2+4*4 . . .

and so on.

Can anyone please help on this? Thank you


Solution

  • Here is the final code I have. Thank you again for the help.

    a=[1;2;3;4];
    b=[8;4;6;7];
    k=[7;4;5;6;7;8;9];
    for j = 1:1:7
        for i = 1:1:4
            m=a(i)+ b(i)*k(j)
        end
    end
    

    Kind regards