Remove the character " * " on a txt file to create a "clean" matrix

4 views (last 30 days)
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
Rahul Kumar
Rahul Kumar on 15 Nov 2020
please rewrite the program and remove '*' this, may this helpful to u
David Martins
David Martins on 15 Nov 2020
Sorry, I didn't understand. The problem that i have is that i need to rewrite what it is inside the dump.txt file in a 3 column matrix.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 15 Nov 2020
S = fileread('dump.txt');
S(S == '*') = '';
A = cell2mat( textscan(S, '%f %f %f', 'headerlines', 3));

More Answers (0)

Community Treasure Hunt

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

Start Hunting!