How can I remove apostrophe from a number?

4 vues (au cours des 30 derniers jours)
Arthur Savioz
Arthur Savioz le 29 Fév 2020
Commenté : darova le 29 Fév 2020
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 commentaires
Arthur Savioz
Arthur Savioz le 29 Fév 2020
For example 12'500
apostrophe is the ' caractere
darova
darova le 29 Fév 2020
YOu can use notepad for removing apostrophe
Just press Ctrl+H

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 29 Fév 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);

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by