MATLAB Matlab fprintf % usage in output data

AI Thread Summary
When using MATLAB's fprintf function, the percent symbol "%" has a special formatting role, which can cause errors when attempting to print it directly. To include a literal "%" in the output, you should use "%%" instead. This allows you to create header text that MATLAB will recognize as a comment when reading the file later. The solution effectively resolves the issue of printing the "%" symbol in the output data. Using "%%" ensures that the header is correctly formatted for future data processing.
karna87
Messages
7
Reaction score
0
Matlab fprintf "%" usage in output data

I want to save data into a textfile, but I will again need MATLAB to read that text file, in which
case, I would like to have my header-text of the data table begin with '%"
so that when I am reading from than file, MATLAB will ignore header.

I am getting error in doing so. Can somebody please help me ?

thank you !
 
Physics news on Phys.org


If I understand correctly, you are encountering an error when trying to print the % symbol using fprintf. That is because % has a special meaning to fprintf. It is used for formatting numbers. If you want to print the symbol itself, you have to put %% instead of %. Example:

fprintf(fid, '%% this is a comment\n');
 


Perfect ! this did help me. I Was trying to print "%". and %% is the solution thanks again
 

Similar threads

Replies
5
Views
7K
Replies
4
Views
3K
Replies
18
Views
6K
Replies
1
Views
3K
Replies
4
Views
1K
Replies
12
Views
2K
Replies
2
Views
2K
Replies
2
Views
1K
Replies
1
Views
2K
Back
Top