필터 지우기
필터 지우기

avoiding nested for loops for matrix assignment

조회 수: 2 (최근 30일)
JAMMI ASHOK
JAMMI ASHOK 2020년 10월 15일
댓글: KSSV 2020년 10월 15일
Hi,
I am a beginner to matlab. Can you please tell me how to avoid using nested for loops in matlab.
THis piece of code is taking lot of space in my hard drive and time.
for i = 1:10000
for j = 1:10000
a(i,j) = i+j
end
end

채택된 답변

KSSV
KSSV 2020년 10월 15일
편집: KSSV 2020년 10월 15일
m = 10000 ; n = 10000 ;
[i,j] = meshgrid(1:n,1:m) ;
a = i+j ;
  댓글 수: 4
JAMMI ASHOK
JAMMI ASHOK 2020년 10월 15일
Yes. If I am initializing it is improving the speed.
KSSV
KSSV 2020년 10월 15일
If you are using a loop and filling the values into matrix......you must initilaize the matrix before loop.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2020년 10월 15일
편집: Matt J 2020년 10월 15일
x = 1:10000;
a = x.' + x;

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by