How to rearrange multiple results of a function without using for loop?

1 回表示 (過去 30 日間)
Toan Nguyen
Toan Nguyen 2020 年 7 月 13 日
回答済み: madhan ravi 2020 年 7 月 14 日
Hi there,
I created function Array(k) which produces an array of 1xN element for the input k.
N = 115824;
Array = linspace(1*k,k*N,N)
I want to apply that function to an array of k = 1:115824. I tried with for loop it but it's very slow.
for k = 1:N
result(k,1:N) = Array(k);
end
Are there any other way to do this task faster and still give me the result as that for loop?
Thank you

採用された回答

Rafael Hernandez-Walls
Rafael Hernandez-Walls 2020 年 7 月 14 日
Assuming that the initial value of k = 1, then it can be avoided using the
repmat
command as follows (see vector B),
N = 11;
k=1;
Array = linspace(1*k,k*N,N)';
for k=1:N
result(k,1:N) = Array(k);
end
B = repmat(Array,[1 N])

その他の回答 (1 件)

madhan ravi
madhan ravi 2020 年 7 月 14 日

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by