MATLAB: Writing a matrix without loop

matrix+loop

Dear all I want to write a matrix that its arrays are dependent on i and j, could I write it without writing loops. my arrays are something like it a(i,j)=sin(2*pi*(i-1))/((sin(2*pi*(i-1))+sin(2*pi*(j-1))))). Thanks

Best Answer

Use meshgrid:
m = 0:20;
n = 0:4;
[x y] = meshgrid(m, n);
a = sin(2*pi*y) ./ ((sin(2*pi*y) + sin(2*pi*x)))
imagesc(a);
set(gca, 'ydir', 'reverse');