Gistlib Logo

gistlib

recreate a basic sscanf.m using regular expressions in matlab

main.m
function data = my_sscanf(input_str, format)

    % Find all the tokens 
    tokens = regexp(input_str, format, 'tokens');

    % Initialize data
    data = cell(1, numel(tokens));

    % Extract data from matched tokens
    for i = 1:numel(tokens)
        data{i} = tokens{i}{1};
    end

end
294 chars
15 lines

similar matlab code snippets

switch the case of letters so that 'hello' becomes 'hello' in matlab
how to input data from website to matlab in matlab
check if string contains number 1 in matlab
list all files in folder that contain the string "abc" inside in matlab
regular expression to fin c++ comments in matlab
remove characters in a string in matlab
difference between strfind() and regexp() in matlab
how to strcat multiple strings inside a string in matlab
print first element of cell to screen with text in matlab
make a regex expression to select only numbers and commas in matlab

related categories

regex
string-manipulation

gistlibby LogSnag