Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 替换包含';#的每个字符串';_Matlab - Fatal编程技术网

Matlab 替换包含';#的每个字符串';

Matlab 替换包含';#的每个字符串';,matlab,Matlab,我有一个包含字符串的单元格数组,如下面的dataT1。如何将包含“#”的所有字符串替换为字母“O”,而不替换其他内容(字符串中没有数字) 您可以使用一个简单的循环 如果要将#替换为O,请使用以下方法: for c = 1:numel(data) % check for character array type in case cell also has numeric values if ischar(data{c}) % replace hashes with

我有一个包含字符串的单元格数组,如下面的dataT1。如何将包含“#”的所有字符串替换为字母“O”,而不替换其他内容(字符串中没有数字)


您可以使用一个简单的循环

如果要将
#
替换为
O
,请使用以下方法:

for c = 1:numel(data)
    % check for character array type in case cell also has numeric values
    if ischar(data{c})
        % replace hashes with 'O'
        data{c} = strrep(data{c}, '#', 'O');
    end
end
如果要将包含
#
的整个字符串替换为仅包含
'O'
的字符串,请使用以下命令:

for c = 1:numel(data)
    % check for character array type in case cell also has numeric values
    if ischar(data{c})
        % Search for # within string
        if strfind( data{c}, '#' ) > 0
            % replace string with 'O'
            data{c} = 'O';
        end
    end
end
for c = 1:numel(data)
    % check for character array type in case cell also has numeric values
    if ischar(data{c})
        % Search for # within string
        if strfind( data{c}, '#' ) > 0
            % replace string with 'O'
            data{c} = 'O';
        end
    end
end