フィルターのクリア

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

7 ビュー (過去 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::
H G J
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');
Result
>> 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 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 9 月 30 日
Yes, ? make more sense here. Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by