MATLAB: Uninterrupted segment length uninterrupted segments Let's say I have an array indexes: Indexes = [1122221122111211112222222] How do I get the length of uninterrupted 2s? I want to output to be output=[ 4 2 1 7] Best Answer For a number that has longer digits, I am not sure. However, if it is within acceptable number of digitsformat longIndexes = [112222112211121];newIndexes=str2double(regexp(num2str(Indexes),'\d','match'))coffee = find(diff([-1 newIndexes -1]) ~= 0);length = diff(coffee);output = length(1+(newIndexes(1)==1):2:end);The output is:output = 4 2 1 Related SolutionsMATLAB: Draw uninterrupted lines on a plot with missing values idx = ~any(isnan(y),1);plot(x(idx),y(idx));Also, you could use nanmean() to get the mean in the presence of NaN's. MATLAB: Hello, I want to derive from a function such as (f=f0+R*f1+R^2*f2+R^3*f3) so that the answer is as follows: (f’=f0’+R*f1’+R^2*f2’+R^3*f3′) syms f(x) f0(x) f1(x) f2(x) f3(x) Rfun=diff(f,x)==diff(f0,x)+R*diff(f1,x)+R^2*diff(f2,x)+R^3*diff(f3,x) Related QuestionLongest segment of successive numbers of a sequenceHow Can i sum same values in an arry untill it change to a diffrent number and sum these aswellCalculate the length of symbolic expressionForce Index to be in range
Best Answer