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