How can I remove apostrophe from a number?
4 views (last 30 days)
Show older comments
I want to rad data from a text file. But I got a problem : MATLAB can't read a number with an apostrophe (158'289.641000 for example).
I want to convert it into that number : 158289.641000
This code works until the first number with apostrophe :
fid= fopen('test.txt', 'r');
rawdata= textscan(fid, '%s %s %s', 'headerlines', 44);
fclose(fid)
tmel = rawdata{1,1};
Imel = rawdata{1,3};
Tank you
5 Comments
Accepted Answer
Image Analyst
on 29 Feb 2020
This works
fullFileName = fullfile(pwd, 'MATBIP_04_Channel_1.txt');
% Open the file for reading in text mode.
fileID = fopen(fullFileName, 'rt');
% Read the first line of the file, but don't use this header line.
textLine = fgetl(fileID);
% Read the second line of the file.
textLine = fgetl(fileID);
lineCount = 0;
while ischar(textLine)
lineCount = lineCount + 1;
% Print out what line we're operating on.
fprintf('%s\n', textLine);
% Get rid of quotes
textLine(textLine == '''') = [];
% Parse string into numbers.
numbers(lineCount, 1:3) = sscanf(textLine, '%f %f %f');
% Read the next line.
textLine = fgetl(fileID);
end
% All done reading all lines, so close the file.
fclose(fileID);
0 Comments
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!