writing a matrix without loop
11 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Image Analyst
2012-12-23
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');
3 个评论
Image Analyst
2012-12-26
x = randi(9, [8 1]) % Random, sample data.
iMinus1 = 0:11
a = x * iMinus1
更多回答(1 个)
Laura Proctor
2012-12-23
Yes, you can create this matrix without using a loop. Use array based mathematical expressions such as ./ and .*
a = sin(2*pi*(ii-1))./(sin(2*pi*(ii-1))+sin(2*pi*(jj-1)));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!