Borrar filtros
Borrar filtros

Unable to read data from text file in matlab

3 visualizaciones (últimos 30 días)
Tankeswar Kumar
Tankeswar Kumar el 12 de En. de 2023
Editada: Bora Eryilmaz el 12 de En. de 2023
clc;
clear all;
close all;
fid = fopen('eeg.txt');
A = fscanf(fid,'%f');
fclose(fid);
when I am trying for run the code I got the following error:
Error using fscanf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in eeg (line 5)
A = fscanf(fid,'%d');
Kindly help me to get rid of this issue.
  1 comentario
Cameron
Cameron el 12 de En. de 2023
Can you attach the file in question? It's hard to do anything without that.

Iniciar sesión para comentar.

Respuestas (1)

Bora Eryilmaz
Bora Eryilmaz el 12 de En. de 2023
Editada: Bora Eryilmaz el 12 de En. de 2023
The file your are looking for is probably not there, or at least, not on the MATLAB path. See what fid is: if it is -1, then you haven't really opened the file, which would result in the error that you are observing:
fid = fopen('badfile.txt')
fid = -1
fscanf(fid, '%f')
Error using fscanf
Invalid file identifier. Use fopen to generate a valid file identifier.
To double check if the file is accessible by MATLAB, run:
exist('eeg.txt', 'file')

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by