Can you vectorize this code?

1 visualización (últimos 30 días)
Bryana
Bryana el 15 de Abr. de 2014
Editada: Jan el 15 de Abr. de 2014
This comes from the Matlab book and I'm having the hardest time understanding it.
Chapter 5, problem 35
Vectorize this code:
n = 3;
x = zeros(n);
y = x;
for i = 1:n
x(:,i) = i;
y(i,:) = i;
end
Please help!

Respuesta aceptada

lvn
lvn el 15 de Abr. de 2014
Editada: lvn el 15 de Abr. de 2014
n=3;
x=meshgrid(1:n,1:n);
y=x';

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 15 de Abr. de 2014
Editada: Azzi Abdelmalek el 15 de Abr. de 2014
Use repmat function

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by