0
votes

I have a 150X1 cell array. Within the array there are multiple data types. The first cell contains 0.9VA = 1.012207; the second: 0.9VA_CLK = 0.020752; and so on like this (for the most part). I would like to split the cell into two cells using the = as the delimiter. Thus, {1,1}: 0.9VA and {1,2}: 1.012207; {2,1}: 0.9VA_CLK and {2,2}: 0.020752; so on and so forth. I have tried converting them to strings and then using strsplit; however, I run into problems because the string arrays are variable in size.

If there is any other information that I can provide please let me know. Thank you for your help and time in advance.

enter image description here

1
When you say "The first cell contains 0.9VA = 1.012207", is that a string (or character array)? - Cris Luengo
It doesn't specify. Sorry, I am in my infancy for this language. I have seen a cell contain something like 1X3 string in the past, but in this case it is just the raw data in the cell. - Dymaxion Fuller
I added an image. This is what I see when I open the 150X1 array. - Dymaxion Fuller
What does class(my_cell_array{1}) say? What does size(my_cell_array{1}) say? (of course, replace my_cell_array with the name of your cell array...) - Cris Luengo
Ahh, perfect! class(my_cell_array{1}) = char. size(my_cell_array{1}) = 1 38. - Dymaxion Fuller

1 Answers

0
votes

You can indeed apply strsplit to each of the strings (char arrays) in the cell array. To do so, you can use cellfun:

c{1} = '0.9VA = 1.012207';
c{2} = '0.9VA_CLK = 0.020752';
c{3} = 'CSIPhgenSWoffList = [0, 0, 0, 0]';
c{4} = 'SomethingElse = [0.020752, 0.24564]';
c = cellfun(@(x)strsplit(x,'='),c,'UniformOutput',false);
c = cat(1,c{:});

I use a small example cell array c here, containing four strings, I hope this is representative. I apply strplit to each cell in c using cellfun(x,'='), which splits at the equal sign and returns a cell array with cell arrays. That is, each string in c is turned into a cell array with 2 strings (e.g. '0.9VA ' and ' 1.012207'. This does leave some spaces at the beginning and end of the strings.

The next line, cat, converts this cell array of cell arrays into a two-dimensional cell array. The final output is a cell array c containing the same number of rows as the original cell array, and with 2 columns. The first column corresponds to the part before the equal sign, the second column to the part after the equal sign.

To remove the spaces, you can use cellfun again, with strtrim:

c = cellfun(@strtrim,c,'UniformOutput',false);