Can you vectorize this code?

1 回表示 (過去 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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by