Create equally spaced 2-d array
26 次查看(过去 30 天)
显示 更早的评论
I want to create an array, say n-by-100*n. I want the first column to be 1,2,...n, and the last column to be 2*pi,2*2*pi,...,n*2*pi, with linear spacing horizontally, similarly to the linspace function. What is the best way to do this? It tried something along the lines of:
arrayName = zeros(n, 100*n);
for k = 1:n
arrayName(k,:) = linspace(0,k*2*pi,100*k);
end
and it didn't work. Any suggestions?
0 个评论
采纳的回答
Mohammad Abouali
2014-12-5
编辑:Mohammad Abouali
2014-12-5
arrayName=bsxfun(@times,(1:n)',linspace(1,2*pi,100*n))
0 个评论
更多回答(1 个)
Azzi Abdelmalek
2014-12-5
编辑:Azzi Abdelmalek
2014-12-5
Your code is correct, you've just mistaken in the line [arrayName(k,:) = linspace(0,k*2*pi, 100*k )], you should write 100*n instead of 100*k
arrayName = zeros(n, 100*n);
for k = 1:n
arrayName(k,:) = linspace(0,k*2*pi,100*n);
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!