MATLAB: How to mat2cell the array cell arraycell arrays Suppose I have this: v= {1 8 1 1 6 1 2 5 3 2 7 11 7 9 10 9}; How can I mat them as below? ( with array start and end as same number) v= { [1 8 1] [1 6 1] [2 5 3 2] [7 11 7] [9 10 9] }; Best Answer >> v = {1,8,1,1,6,1,2,5,3,2,7,11,7,9,10,9};>> c = regexp(char([v{:}]),'(.).*?(??$1)','match');>> c = cellfun(@double,c,'uni',0);>> c{:}ans = 1 8 1ans = 1 6 1ans = 2 5 3 2ans = 7 11 7ans = 9 10 9 Related SolutionsMATLAB: Is it possible to extract the values with a vector of indices for each row without using the for statement from the matrix see sub2ind()A = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]; % reference matrixb = [2; 1; 1; 3]; % index for each row that I want to extractidx = sub2ind(size(A), 1:size(A,1), b.');A(idx)Result>> A(idx)ans = 2 4 7 12 MATLAB: Rearrange an array based on a matrix Would something like this work:for i = 1:numel(V) [~,k] = find(M == V(i)); col_v = M(:,k); col_v = col_v(col_v ~= 0); ridx = randi(numel(col)); V(i) = col(ridx);end Related QuestionDivide an array in n different arraysHow could I check that how many elements of x is inside yHelp running Matlab scriptConvert a 1*16 matrix to a 2*8 matrixHow to creat two box plot in one graph use different dataCount the number of same elements in an array
Best Answer