Can you vectorize this code?

조회 수: 5 (최근 30일)
Bryana
Bryana 2014년 4월 15일
편집: Jan 2014년 4월 15일
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!

채택된 답변

lvn
lvn 2014년 4월 15일
편집: lvn 2014년 4월 15일
n=3;
x=meshgrid(1:n,1:n);
y=x';

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 15일
편집: Azzi Abdelmalek 2014년 4월 15일
Use repmat function

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by