Filter löschen
Filter löschen

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

21 Ansichten (letzte 30 Tage)
doaa
doaa am 29 Okt. 2022
Bearbeitet: Bhanu Prakash am 23 Feb. 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 Kommentare
Jan
Jan am 29 Okt. 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 am 9 Nov. 2022
Bearbeitet: SWARNENDU MONDAL am 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+');
My upload and changes

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Bhanu Prakash
Bhanu Prakash am 16 Feb. 2023
Bearbeitet: Bhanu Prakash am 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.

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by