trying to obtain data from a txt file but one column has negative values and ignores the - sign and leaves it as +

조회 수: 26(최근 30일)
str = fileread('Wello.txt');
nums = cellfun(@str2double, regexp(str, '([\d.,]+)', 'match'));
DATA = reshape(nums, 3, [])';
this is the code above.
txt file is like this::
245 54 -45
output after code:
245 54 45

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 30일
편집: Ameer Hamza 2020년 9월 30일
Why use regular expression here. Just use readmatrix()
M = readmatrix('data.txt');
>> M
M =
245 54 -45
For the regular expression in your question, you missed the minus (-) sign
str = fileread('data.txt');
nums = cellfun(@str2double, regexp(str, '(-?[\d.,]+)', 'match'));
  댓글 수: 3

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

추가 답변(0개)


Community Treasure Hunt

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

Start Hunting!

Translated by