matlab - How to select rows from character array that match char string and save them in a new array? -


i have char array contains list of files names (each row 1 file) (char, 526x26)

val =  0815_5275_uba_a_1971.txt   0815_5275_uba_a_1972.txt   0823_6275_uba_a_1971.txt   0823_6275_uba_a_1972.txt   0823_6275_uba_a_1973.txt ... 

i have variable

b = '0815_5275'  

i'd select rows (filenames) start b , save them in new array c.

this should simple, somehow can't make work. i've got this:

c = a(a(:,1:9) == b); 

but error message:

error using  ==  matrix dimensions must agree. 

i not know in advance how many rows match, can not pre-define empty array.

thanks, appreciated!

try ismember(a(:, 1:numel(b)), b, 'rows') rather logical vector indexes rows want

and now

a(c,:) extract rows

the reason you're getting dimension mismatch error because a(:,1:9) has many rows b has 1 , matlab not automatically broadcast octave or python. using either repmat or bsxfun in case ismember correct function choose.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -