|
From: | William Krekeler |
Subject: | structure array string extraction |
Date: | Thu, 9 Dec 2010 19:56:39 +0000 |
I want to extract a subset of a string from each string in
an array of strings inside a structure. I gave an example below of the simplest
case of the data structure. How can I use the cell array of indexes to pull out the
subset string from each array element string? I am specifically trying to avoid
using a for loop. Any help on making this method more eloquent/better would be
appreciated. Given the following test structure: test(1).string = '123_abc_46_f.tif'; test(2).string = '123_abce_45_f.tif'; test(3).string = '123_abce_3_f.tif'; test(4).string = '123_abce_56_f.tif'; startIndex = regexpi( { test(:).string }, '[a-z]_' ), % get
start indices of string you want to extract endIndex = regexpi( { test(:).string }, '_f' ) %
get end indices of string you want to extract % output of run startIndex = { [1,1] = 7 [1,2] = 8 [1,3] = 8 [1,4] = 8 } endIndex = { [1,1] = 11 [1,2] = 12 [1,3] = 11 [1,4] = 12 } % covert to numeric startIndex = cell2mat( startIndex ) + 2; endIndex = cell2mat( endIndex ) - 1; % pseudo code below don’t know how to do this. Array_Numbers = str2num( test(:).string( startIndex:endIndex
) ) Above gives error: error: can't perform indexing operations
for cs-list type Bill
Krekeler |
[Prev in Thread] | Current Thread | [Next in Thread] |