How can I remove apostrophe from a number?

조회 수: 4 (최근 30일)
Arthur Savioz
Arthur Savioz 2020년 2월 29일
댓글: darova 2020년 2월 29일
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
Arthur Savioz
Arthur Savioz 2020년 2월 29일
For example 12'500
apostrophe is the ' caractere
darova
darova 2020년 2월 29일
YOu can use notepad for removing apostrophe
Just press Ctrl+H

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2020년 2월 29일
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개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by