Can you vectorize this code?

2 vues (au cours des 30 derniers jours)
Bryana
Bryana le 15 Avr 2014
Modifié(e) : Jan le 15 Avr 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!

Réponse acceptée

lvn
lvn le 15 Avr 2014
Modifié(e) : lvn le 15 Avr 2014
n=3;
x=meshgrid(1:n,1:n);
y=x';

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 15 Avr 2014
Modifié(e) : Azzi Abdelmalek le 15 Avr 2014
Use repmat function

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by