fiq10
fiq10

Reputation: 1

How to use 'fprintf' to show the output in a txt file and save it instead of command window in Matlab?

I've been trying to make the output shown in the text file instead of the command window. Im blur right now as i already look at a lot of example but it always show the error on fprintf. I try to edit the code of fprintf(fid,'%s\n',word);%Write 'word' in text file (upper) in one of the Matlab example which is Automatically Detect and Recognize Text in Natural Images.

This is the link of the code. https://www.mathworks.com/help/vision/examples/automatically-detect-and-recognize-text-in-natural-images.html?s_tid=srchtitle

Basically the above link display the output on the command window. But, i need it to be on the txt file.

Im really new to this, i want to know what code do i need to put, how and where should i put the fprintf to make the output shown on the text file and not on the command window.

Also, can i save the text file after that? do i to put any additional code?

I really need your help. Thank u in advance!

Upvotes: 0

Views: 862

Answers (1)

HunterTheGatherer
HunterTheGatherer

Reputation: 161

It seems you're looking for the fopen() method. It takes two parameters, the first being the name of the file you'd like to write to, and the second being the mode. If the file specified does not exist in the root directory, it will be created on execution.

fileID = fopen('exp.txt','w');
fprintf(fileID, fid,'%s\n', word);
fclose(fileID); % Make sure to always close the stream after finishing

More on fopen() here

Upvotes: 3

Related Questions