Can you vectorize this code?

5 visualizzazioni (ultimi 30 giorni)
Bryana
Bryana il 15 Apr 2014
Modificato: Jan il 15 Apr 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!

Risposta accettata

lvn
lvn il 15 Apr 2014
Modificato: lvn il 15 Apr 2014
n=3;
x=meshgrid(1:n,1:n);
y=x';

Più risposte (1)

Azzi Abdelmalek
Azzi Abdelmalek il 15 Apr 2014
Modificato: Azzi Abdelmalek il 15 Apr 2014
Use repmat function

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by