0
votes

So here is my problem:

I have a list of names in Matlab in a cell array.

I automatically create directories and .mat files for each name.

My problem is that some of these names contains '/' and therefore everything go wrong when I create the directory…

So I am trying to find an efficient way to find '/' and replace them.

So far I've tried to find them using the findstr function. It then gives me a cell array with the indexes where '/' appears. So when the name doesn't contain any '/' it returns {[]} and when the function find it, it returns {[i]}. Now i'd like to have a logical condition that says if findstr is not empty then do something. I've tried with the isempty function but it doesn't work (it's never empty…)

So does anyone have a solution to this?

Thanks

1
What would be the replacing character? - Luis Mendo
Can you show us the code you tried so far? - Peanut

1 Answers

1
votes

Use regexprep to replace the character:

list = {'aaa', 'bb/cc', '/dd/'};
replace_from = '/'; %// character to be replaced
replace_to = '_'; %// replacing character
list_replaced = regexprep(list, replace_from, replace_to);

gives

list_replaced = 
    'aaa'    'bb_cc'    '_dd_'