Vectorize operations based on column and row indicies
Vectorize thisfor i = 1:100 for j = 1:100 r(i,j) = sqrt(i^2+j^2); end end
becomes
[i,j]=meshgrid(1:100,1:100); r = sqrt(i.^2+j.^2);
Matlab Snippets > row >
Post Matlab code snippets. Sort by tags, people, people and tags, etc.. Brought to you by XTargets - Consulting & Application devlopment.
Vectorize operations based on column and row indiciesVectorize thisfor i = 1:100 for j = 1:100 r(i,j) = sqrt(i^2+j^2); end end becomes [i,j]=meshgrid(1:100,1:100); r = sqrt(i.^2+j.^2); Reverse one column or row of a matrixTo reverse column or row c of a Matrix MM(:,c)=flipud(M(:,c)) M(c,:)=flipud(M(c,:))
|
|