MATLAB: How to update matrix values using algorithm based on position matrix algorithm Suppose I've already create a square matrix, A=zeros(n). Now let's say, for every position, A(i,j), I want to update the value to 1 / (i + j^2), can I do this easily? Thanks! Best Answer The straightforward way is to just use a loop:A = zeros(n);for ii = 1:n for jj = 1:n A(ii,jj) = 1/(ii+jj^2); endendHere is another way to do it:B = bsxfun(@(x,y) 1./(x+y.^2),(1:n).',1:n) Related SolutionsMATLAB: Creating a matrix with for and input nnd=input('Enter nnd ');... geom(i,j)=input('Enter the Value: ')'..geom MATLAB: Manipulating Matrix elements based on their index without using a for loop. [jj,ii]=meshgrid(1:n,1:n);A((ii-n/2).^2+(jj-n/2).^2>n)=0 Related QuestionHow to control Uitable scroller positionHow to stop getting cursor positionI have an all zero matrix ‘a’ of size m x n. In a new 2 column matrix ‘b’ I have the indices where I should replace the zero in ‘a’ with 1. Is there a way to do this without a ‘for’ loop? The m,n > 500..Efficient way of transforming vectorHow to write matrix elements with its position
Best Answer