I am trying to run a MATLAB code in Octave. There is a MATLAB function extractBetween that is not yet available in octave. Original code is
numbers = str2double(extractBetween(dirAndFileNames(:,2), 4, 5));
I have tried to replace it with this code.
numbers = str2double(substr(dirAndFileNames(:,2), 4, 2));
It works for single strings but not for cell arrays. I have tried other functions that work with cell arrays like strtrim, strtrunc. I want to extract the numbers on the end but strtrunc gives opposite of what I want. It gives the first letters.
dirAndFilenames(:,2) looks like this:
debug> dirAndFileNames(:,2)
ans =
{
[1,1] = desktop.ini
[2,1] = trn01
[3,1] = trn02
[4,1] = trn03
[5,1] = trn04
[6,1] = trn05
[7,1] = trn06
[8,1] = trn07
[9,1] = trn08
[10,1] = trn09
[11,1] = trn10
}
As @cris suggested, i had to loop over.
for i = 1:length(dirAndFileNames)
numbers{i} = str2double(substr(dirAndFileNames(i,2){1}, 4, 2))
end
You can use cellindexmat :
a = dirAndFileNames(:, 2);
result = cellindexmat(a, 4:5);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With