Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Script stops running after reaching blank value during import

조회 수: 1 (최근 30일)
Mitchell Cayzer
Mitchell Cayzer 2019년 10월 10일
마감: MATLAB Answer Bot 2021년 8월 20일
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&&

답변 (1개)

John Doe
John Doe 2019년 10월 10일
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