MATLAB: How can I add a value to a particular cell in an array. MATLAB if [3,2,4,5;3,2,6,4;2,5,8,5] is array then we add we add 2 to the second row to become [2,3,2,5;3, 4,6,4;2,5,8,5] Best Answer if A is your array,>> A = [3,2,4,5;3,2,6,4;2,5,8,5]A = 3 2 4 5 3 2 6 4 2 5 8 5and if you want to add 2 to 2nd row, 2nd column, A(2,2) = A(2,2)+2;and then A becomes, A = 3 2 4 5 3 4 6 4 2 5 8 5is this what you mean? Related SolutionsMATLAB: How to calculate the mean of the elements values of the array according to objects of the other array. A is your labeled matrix. B is your intensity matrix. Use regionprops() (in the Image Processing Toolbox) and ask for MeanIntensity:A = [3 3 3 3 1 1 1 1 1 1 8 8; 3 3 3 5 1 1 1 1 1 8 8 8; 3 3 3 5 5 1 1 1 8 8 8 8; 3 3 3 5 5 5 1 8 8 8 8 8; 7 7 7 5 5 5 6 6 6 8 8 8; 7 7 7 5 5 5 6 6 6 4 4 4; 7 7 2 2 2 6 6 6 6 4 4 4; 7 2 2 2 2 6 6 6 6 4 4 4; 2 2 2 2 2 2 6 6 4 4 4 4]B = [5 4 4 3 7 5 8 8 7 9 4 8; 6 8 9 4 2 3 6 7 7 7 6 8; 7 2 4 7 7 9 4 2 4 8 8 9; 8 2 4 2 6 5 2 8 1 1 7 9; 4 8 2 8 8 3 2 2 6 2 5 8; 1 1 3 1 6 4 5 6 2 7 3 1; 7 7 3 5 9 7 4 5 7 7 7 1; 3 7 9 1 4 4 7 2 5 7 4 1; 8 4 3 7 4 2 1 1 3 5 6 3]props = regionprops(A, B, 'MeanIntensity')allIntensities = [props.MeanIntensity]C = zeros(size(A))for k = 1 : max(A(:)) C(A==k) = allIntensities(k);endC % Print to command window. MATLAB: Ranking of an array. I assume, the result should be [2 4; 5 6; 3 1] with the last two elements swapped. The method is called sorting, not ranking.M = [1,5; 7 9; 2 0];[dummy, index] = sort(M(:));R(index) = 1:numel(M);R = reshape(R, size(M)); Related QuestionSubtracting 2 matrices of different dimensionsSum columns of matrixCall all element inside cell (this cell contain another set of cells)Nearest value from an array.
Best Answer