MATLAB: How can I link 4 vectors based on their length? that is from the longest to the shortest arrayconcatenatelength vectorMATLAB I.e. I have a=[5 5 5 5 5], b=[4 4 4 4], c=[3 3 3] and d=[2 2]. I want to concatenate out=[a b c d] without knowing, however, the length of a, b, c, d in each cycle. Thank you. Best Answer values = {a, b, c, d}; lens = cellfun(@length, values); [~, idx] = sort(lens, 'descend'); out = [values{idx}]; Related SolutionsMATLAB: LONGEST PATH BY PRODUCT You can take the log of your inverse matrix and use the log property:Which basically says that maximizing/minimizing the sum (of logs) is the same as maximizing/minimizing the product of the variables. MATLAB: Finding longest consecutive numbers in array If you have the Image Processing Toolbox you can use bwareafilt() along with diff() and do it like this:myarray = [1999 2000 2001 2003 2004 2005 2006 2007]result = find(bwareafilt([0, diff(myarray)] == 1, 1)) % Returns [5,6,7,8]result = [result(1)-1, result] % Prepend right most element index 4.You see:myarray = 1999 2000 2001 2003 2004 2005 2006 2007result = 5 6 7 8result = 4 5 6 7 8 Related QuestionDetect longest line in an imageLongest simple path between 2D pointsGiven a cell array, find the longest string
Best Answer