text = fread(file, '*char')';
20 views (last 30 days)
Show older comments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% "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 Comments
Jan
on 29 Oct 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
on 9 Nov 2022
Edited: SWARNENDU MONDAL
on 9 Nov 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+');
Answers (1)
Bhanu Prakash
on 16 Feb 2023
Edited: Bhanu Prakash
on 23 Feb 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.
0 Comments
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!