Remove the character " * " on a txt file to create a "clean" matrix
4 views (last 30 days)
Show older comments
David Martins
on 15 Nov 2020
Commented: David Martins
on 15 Nov 2020
Hi guys.
Let me start wishing that everyone is ok due to COVID pandemic.
I have a .txt file with an excess of " * " carachters. What i want to do is to get rid oh those and create an 3 column matrix containing only the numbers. At this moment i have this:
clc;
clear all;
close all;
[name,path]=uigetfile('.txt','Select File To Open');
file=[path,name];
A=textread(file,'%f %f %f',1,'headerlines',3,'delimiter','*');
and it gives me the following error:
Error using dataread
Number of outputs must match the number of unskipped input fields.
Error in textread (line 171)
[varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1>
Error in Untitled (line 9)
A=textread(file,'%f %f %f',1,'headerlines',3,'delimiter','*','whitespace','');
I don't know how to fix so if you could help me i'll appreciated. I've attached the txt file.
Thanks in advance a please, stay safe.
2 Comments
Accepted Answer
Walter Roberson
on 15 Nov 2020
S = fileread('dump.txt');
S(S == '*') = '';
A = cell2mat( textscan(S, '%f %f %f', 'headerlines', 3));
More Answers (0)
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!