Matlab loop exception

Here is a simple question. The next nested for loop creates an array of sine wave values.

N = 2^16;
for m = 1:10;
    for i = 1:N
        sine(m,i) = sin(2*pi*i./(8*2^m));
    end
end

It seems that I would have to create this array without using for loops, but I tried various syntaxes and always got an error message. Thanks in advance for any ideas.

+4
source share
3 answers

You can use bsxfunas follows:

sine = sin(bsxfun(@times, 2*pi*(1:2^16), 1./(8*2.^(1:10))' ));
+6
source

Try the following:

ii = 1:2^16;
m  = [1./(2.^(1:10))].'% transpose

prefactor = 2 * pi / 8;

sine = sin(prefactor * m * ii);

A*B, a - , B - ncols , nkn. , m - ii .

+5

Try using ndgrid

N=2^16;
[M, I] = ndgrid(1:10, 1:N);
sine = sin(2*pi*I./(8*2.^M));
+4
source

All Articles