Vector programming of sum (greek sigma)
조회 수: 4 (최근 30일)
이전 댓글 표시
I have this code:
I want to do it in vectorised programming but I cannot get it to run:
%generate the two random matrices with different height
h1 = 'h1';
disp('enter a number for h1, which is the height of the random matrix')
h1 = input(h1);
A = rand(h1, 200);
%method one
timer1 = tic;
the_sum=0;
for h=1:h1
for w=1:200
the_sum=the_sum+A(h, w);
end
end
toc(timer1)
%method two
timer2 = tic;
h=1:h1,w=1:200;
the_sum2=the_sum2A(h, w)
toc(timer2);
thesum
Thanks for any help
댓글 수: 0
채택된 답변
Roger Stafford
2013년 9월 4일
It looks as though this is what was meant:
%method two
timer2 = tic;
the_sum2 = sum(sum(A,2),1);
toc(timer2);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Labels and Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!