MATLAB: Add a zero element to the beginning of each existing cell array cellfun I have C={[-8;-5],[1;-4;-5;-5;-5],[-3;-5]} I want to get this result CC={[0;-8;-5],[0;1;-4;-5;-5;-5],[0;-3;-5]} I use this code, but do not works c = cellfun(@(x)(x(0)==0), a, 'UniformOutput', false); Best Answer cellfun(@(v)[0;v],C,'uni',0)And checking:>> C = {[-8;-5],[1;-4;-5;-5;-5],[-3;-5]};>> CC = cellfun(@(v)[0;v],C,'uni',0);>> CC{:}ans = 0 -8 -5ans = 0 1 -4 -5 -5 -5ans = 0 -3 -5 Related SolutionsMATLAB: Find element in array Not sure how you get the result, but here is an attemptDataE=[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13; 7 8;7 9;9 10;9 14;10 11;12 13;13 14]C={[1,2,4,5],[1,2,4,5,6,9,10,11],[1,2,4,5,6,13,13]}CodeCC = cellfun(@(s) E(all(ismember(E,s),2),:), C, 'unif', 0);Result:>> CC{:}ans = 1 2 1 5 2 4 2 5 4 5ans = 1 2 1 5 2 4 2 5 4 5 4 9 5 6 6 11 9 10 10 11ans = 1 2 1 5 2 4 2 5 4 5 5 6 6 13 MATLAB: How to modify a matrix to change the entries >=0 and multiply it by 5 AND to change the entries <0 and add 2 to those entries Start with "If an entry in B is greater than or equal to zero": You can either run a loop over all elements of B or use "logical indexing":% Linear indexing:for k = 1:numel(B) if B(k) >= 0 ... endendOr two indices for rows and columns:for r = 1:size(B, 2) for c = 1:size(B, 1) if B(r, c) >= 0 ... end endendOr "logical indexing":index = (B >= 0);disp(B(index))Now try to use this to modify B. Use the mentioned terms to search in the documentation and in the internet. Related QuestionChoose row cell of matrixRemove cell array content matrix with condition: length of element in cell smaller than specific valueCalculate mean using while and iterationHow to solve this? :-/Call all element inside cell (this cell contain another set of cells)Undefined function or variable ‘sigshift’. how can i shift the signal
Best Answer