Splitting Excel column input into 5 at FIXED WIDTH columns

I have data in excel column of format BANKNIFTY03JUN2127800PE.NFO which i want to split at fixed width like - Column 1 : BANKNIFTY, COlumn 2 with date : 03JUN21, COlumn 3 with strike price: 27,800, column 4: PE COlumn5:.NFO. How do i do it ?

2 Comments

@sushil malani: please click the paperclip button and upload an original data file.

Sign in to comment.

 Accepted Answer

filename = 'AppropriateFileName.xlsx';
AppropriateColumnNumber = 7; %change to actual column number
opts = detectImportOptions(filename);
opts = setvartype(opts, AppropriateColumnNumber, 'string');
T = readtable(filename, opts);
TC = T{:,AppropriateColumnNumber};
%comment out any entries you do not need the output for
BANKNIFTY = extractBetween(TC, 1, 9);
date = datetime(extractBetween(TC, 10, 16), 'InputFormat', 'ddMMyy');
strike_price = double(extractBetween(TC, 17, 21));
PE = extractBetween(TC, 22, 23);
NFO = extractBetween(TC, 24, 27);

More Answers (0)

Categories

Products

Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!