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

23 次查看(过去 30 天)
doaa
doaa 2022-10-29
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% "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 个评论
Jan
Jan 2022-10-29
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 2022-11-9
编辑:SWARNENDU MONDAL 2022-11-9
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

请先登录,再进行评论。

回答(1 个)

Bhanu Prakash
Bhanu Prakash 2023-2-16
编辑:Bhanu Prakash 2023-2-23
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.

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by