Delete substring within a fuction
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I'm getting some data from several txt files and turning it into strings. In this case I pretend to delete the words "BEMP [bar]" and then convert the values into a numeric string (1x5). I've tried the erase function but matlab doesn´t recognize it. Any ideas? Also I'm new in matlab, so sorry for the mess...
function [ bmep_th ] = extract_bmep( filename ) %bemp with throttle from txt files
fid = fopen (filename);
for i= 1:243
fgetl(fid);
end
str = fgetl (fid) % get specific line
fclose (fid);
newStr = erase (str,'BMEP'); % I want to delete de words "BMEP [bar]"
newStr = str2num (newStr);
bmep_th = newStr(:,1) % Need the fisrt value - Mean BMEP (in this example -1.5514)
end
>>str = BMEP [bar] -1.5514 -1.5463 -1.5536 -1.5541 -1.5515
0 Kommentare
Antworten (1)
the cyclist
am 4 Feb. 2021
str = '123BEMP456';
newStr = [extractBefore(str,'BEMP'),extractAfter(str,'BEMP')]
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!