Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Script stops running after reaching blank value during import

1 vue (au cours des 30 derniers jours)
Mitchell Cayzer
Mitchell Cayzer le 10 Oct 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
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&&

Réponses (1)

John Doe
John Doe le 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:

Community Treasure Hunt

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

Start Hunting!

Translated by