MATLAB: Repeat all operations for n rows inside an array (with n unknown) arrayMATLABrows Hi everybody, i have an array like this (with unknown rows number): 0.3 0.4 4 0.5 0.6 3.1 and i'd like to repeat different operations for every rows to obtain different results for different row. Thank you! Best Answer M = [0.3 0.4 4; ... 0.5 0.6 3.1];nRow = size(M, 1);for iRow = 1:nRow yourOperation(M(iRopw, :)) ...endIf you want to collect the results, use either a matrix again:result(iRow, :) = ...Or if the output has different sizes or classes, use a cell array:Result = cell(1, nRow);for iRow = 1:nRow Result{iRow} = yourOperation(M(iRopw, :)) ...end Related SolutionsMATLAB: Error: Unable to perform assignment because brace indexing is not supported for variables of this type STRGT=cell(1,nRow); % before the loop ,also move STRAIGHT outside the loop MATLAB: Delete first x number of rows from a cell array >> C = num2cell([randi(9,6,3),[0;0;0;1;2;3]])C = [5] [8] [6] [0] [2] [3] [5] [0] [2] [9] [4] [0] [3] [4] [8] [1] [8] [2] [6] [2] [3] [3] [5] [3]>> C([C{:,4}]>0,:)ans = [3] [4] [8] [1] [8] [2] [6] [2] [3] [3] [5] [3] Related QuestionHow to use unique function in 2D matricesHow to compare each element of an array with the rest of the elements for several rows independentlyUnnecessary rounding when reading an xlsxHow to compare rows of an array with other rowsPdist2 inside forRemove row of matrix inside cellData filtering(Give a constraint to the length of each index )
Best Answer