Borrar filtros
Borrar filtros

text = fread(file, '*char')';

21 visualizaciones (últimos 30 días)
doaa
doaa el 29 de Oct. de 2022
Editada: Bhanu Prakash el 23 de Feb. de 2023
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% "Reading Text Data File" %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tic
fprintf('Reading data: ');
file = fopen('Data/source_data.txt');
text = fread(file, '*char')';
fclose(file);
toc
%%%there are an error in this part i need for help ing
  2 comentarios
Jan
Jan el 29 de Oct. de 2022
If you assume, that there is an error and want others to solve it, it is useful to mention, what you observe. I cannot guess, what you call "error" here. Do you get an error message? If so, post a copy of the complete message.
Add the new information by editing the question, not by appending a comment.
SWARNENDU MONDAL
SWARNENDU MONDAL el 9 de Nov. de 2022
Editada: SWARNENDU MONDAL el 9 de Nov. de 2022
I faced the same problem, but here is one solution. This line
file = fopen('Data/source_data.txt');
will open the file 'source_data.txt', which is present in a inner folder named 'Data'.
If you are simulating online, then you have to upload that file also, and also you have to change the corresponding location.
I have upoladed it with the codes and didn't made anyinnder folder, so I have changed the code to this:
file = fopen('source_data.txt');
Remember you have to chenge another line.
f = fopen('Data/received.txt','w+');
to
f = fopen('received.txt','w+');
My upload and changes

Iniciar sesión para comentar.

Respuestas (1)

Bhanu Prakash
Bhanu Prakash el 16 de Feb. de 2023
Editada: Bhanu Prakash el 23 de Feb. de 2023
Hi Doaa,
As per my understanding, you are trying to perform read operation on a text file.
Based on my assumption, the error might be present in the “fopen” command. For it to work, the text file “source_data.txt” must be present in the MATLAB path or the complete location of the file needs to be passed as an argument to the “fopen” command.
You can access the related documentation of “fopen” command and “adding folders to MATLAB path” here
Hope this answer helps you.
Thanks,
Bhanu Prakash.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by