单元格数组,向每个字符串添加后缀 [英] cell array, add suffix to every string

查看:73
本文介绍了单元格数组,向每个字符串添加后缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含字符串的单元格数组:

Suppose I have a cell array containing strings:

c = {'foo1', 'foo2', 'foo3'}

我现在想向每个字符串添加相同的后缀" bar ",以使单元格数组变为:

I now want to add the same suffix "bar" to each string, such that the cell array becomes:

c = {'foo1bar', 'foo2bar', 'foo3bar'}

在没有显式循环遍历每个元素的情况下,是否存在执行此操作的捷径?

Is there a shortcut to doing this, without explicitly looping through each element?

推荐答案

strcat 对单元格数组进行操作:

strcat operates on cell arrays:

>> c = {'foo1', 'foo2', 'foo3'}
c = 
    'foo1'    'foo2'    'foo3'
>> c2 = strcat(c,'bar')
c2 = 
    'foo1bar'    'foo2bar'    'foo3bar'

这篇关于单元格数组,向每个字符串添加后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆