How can I remove apostrophe from a number?

4 visualizaciones (últimos 30 días)
Arthur Savioz
Arthur Savioz el 29 de Feb. de 2020
Comentada: darova el 29 de Feb. de 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 comentarios
Arthur Savioz
Arthur Savioz el 29 de Feb. de 2020
For example 12'500
apostrophe is the ' caractere
darova
darova el 29 de Feb. de 2020
YOu can use notepad for removing apostrophe
Just press Ctrl+H

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 29 de Feb. de 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);

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by