MATLAB Answers

Script stops running after reaching blank value during import

1 view (last 30 days)
Mitchell Cayzer
Mitchell Cayzer on 10 Oct 2019
Answered: John Doe on 10 Oct 2019
I'm trying to import data programmatically from a file but whenever the file reaches one of the lines without numbers that still contains the formatting the script seems to freeze and finishes running. The code I'm using is below while the contents of the text file are below that. I know that the problem are the lines that consist of $$ & #$ && with no number values because when I pause the script from running the matrix created stops there. Can anyone see what I'm doing wrong or have a solution? Thank you
clear
clc
mat=[]
filename='GroupFTest.txt'
fileID=fopen(filename)
while ~feof(fileID)
nextrow = fscanf(fileID, '$$%f& %f#$ %f&&\n',3);
nextrow = nextrow';
mat = [mat; nextrow];
end
mat
$$0.64& 0.56#$ -0.23&&
$$0.83& 0.72#$ -0.45&&
$$0.73& 0.13#$ -0.04&&
$$0.17& 0.97#$ -0.43&&
$$0.93& 0.67#$ -0.24&&
$$0.48& 0.12#$ -0.36&&
$$0.94& 0.78#$ -0.20&&
$$ & #$ &&
$$0.56& 0.44#$ -0.34&&
$$0.75& 0.43#$ -0.37&&
$$0.65& 0.34#$ -0.46&&
$$0.45& 0.61#$ -0.56&&
$$0.67& 0.12#$ -0.89&&
$$ & #$ &&
$$0.52& 0.87#$ -0.65&&
$$0.23& 0.44#$ -0.34&&

  0 Comments

Sign in to comment.

Answers (1)

John Doe
John Doe on 10 Oct 2019
I use readtable for delimited text files. I've found this to work very well.
Can you share the original format please if you want more specific help.
Here is an example which should solve your problem:

  0 Comments

Sign in to comment.

Sign in to answer this question.