2015-04-23 45 views
2

我有一個像這樣的字符串單元格數組。圍繞一個字符串添加括號

'A' 'B' 'C' 

我想補充圍繞每個所以它的支架變成:

'(A)' '(B)' '(C)' 

我已經試過以下,其中first_term_1是A,但才使得其1×3的細胞是沒有用的對我來說。

new=['(' first_term_1 ')'] 

這整個問題是我使用一組鈍的數學規則生成一個簡化的方程。

回答

4
>> t = {'A', 'B', 'C'}; 
>> strcat('(', t, ')') 
ans = 
    '(A)' '(B)' '(C)' 
1
t = { 'A' 'B' 'C' } 
fcn = @(a) sprintf ('(%s)', a) 
newCell = cellfun (fcn, t, 'UniformOutput', false) 
+0

感謝的是,將這項工作,以及增加逆跡象? fcn = @(a)sprintf('1 /(%s)'),a); output = cellfun(fcn,t,'UniformOutput',false); – Trippy

+0

@Trippy'strcat('1 /(',t'')')' –

2

你很近!只需要使用大括號打破了細胞的出來:

my_strings = {'A','B','C'}; 
new_string = ['(' my_strings{1} ')'];