1

I have cell array with full of string like below

a = 

    'one'      'two' 
    'three'    'four'

now I am assign the above cell array a to another cell array b first , second and third place Like below

b{1} =a;
 b{2} =a;
 b{3} =a;

now i want to combine the string X = '-h'; with each and every string of b cell array

How can I do ?

Example output is

b =        
        {2x2 cell}
        {2x2 cell}
        {2x2 cell};

b{1} ={'one-h' 'two-h' ;'three-h'  'four-h'};
b{2} ={'one-h' 'two-h' ;'three-h'  'four-h'};
b{3} ={'one-h' 'two-h' ;'three-h'  'four-h'};

but I need this output after assign the a value to b like step 2 (b{1} = a...) and string X must combine with b cell array only

0

1 Answer 1

1

Try this:

%// Using nested cellfun
b = cellfun(@(x) cellfun(@(y) strcat(y,'-h'),x,'Uni',0),b,'Uni',0);

Output:

>> b{1}

ans = 

'one-h'      'two-h' 
'three-h'    'four-h'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.