Borrar filtros
Borrar filtros

Create equally spaced 2-d array

24 visualizaciones (últimos 30 días)
Michael
Michael el 5 de Dic. de 2014
Editada: Azzi Abdelmalek el 5 de Dic. de 2014
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?

Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 5 de Dic. de 2014
Editada: Mohammad Abouali el 5 de Dic. de 2014
arrayName=bsxfun(@times,(1:n)',linspace(1,2*pi,100*n))

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 5 de Dic. de 2014
Editada: Azzi Abdelmalek el 5 de Dic. de 2014
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

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by