0
votes

I have a cell with strings in the following format:

data = {'para1_left = numeric value';'para1_right = numeric value';
        'para2_left = numeric value';'para2_right = numeric value';
        ........
        'para100_up = numeric value';'para100_down = numeric value';
         and so on...I have a few hundreds of these};

I want two cells out of this cell: one with just the parameter names, p_name, and another with just the values, p_val.

Once I have the two cells, I want to compare the p_name cell with another cell of shorter length. This new cell will have strings in the following format:

new_cell = {'para1';'para5';'para10';...'para25'};

Basically these strings miss the trailing parts: _left, _right, etc.

Then, I want to have a list of indices of p_name that contain any of the strings in new_cell, indx_match = [1;2;10;20....and so on] so that I can get the values of the matching parameter names by doing p_val{indx_match}.

I want to do the above with the minimum number of lines, probably using cellfun. I figured out how to find the indices by using strfind command, but then it creates a cell array and p_val{indx_match} doesn't work (I tried various ways using cellfun, but no success yet).

1

1 Answers

0
votes

I'm not sure exactly what you want, but this should get you on the right track.

Org = {'a_l = 5'; 'a_r = 7'; 'b_l = 6'; 'b_r = 7'};
Shr = {'a'};
splt = cellfun(@(s) strsplit(s, {'=', ' '}), Org, 'uni', 0);
p_name = cellfun(@(c) c{1}, splt, 'uni', 0);
p_val = cellfun(@(c) str2num(c{2}), splt);
param = cellfun(@(c) strsplit(c, '_'), p_name, 'uni', 0);
param = cellfun(@(c) c{1}, param, 'uni', 0);
index = cellfun(@(s) strfind(param, s), Shr, 'uni', 0);