フィルターのクリア

MATLAB Simulink fprintf logical values

19 ビュー (過去 30 日間)
Tan Biru
Tan Biru 2014 年 8 月 25 日
回答済み: Michael Haderlein 2014 年 8 月 25 日
Greetings,
May I know what is the suitable formatSpec for type 'logical'? I am running this in Simulink, Matlab 2014a.
The code:
a1 = (u > min_u); fileID = fopen('C:\Users\Desktop\myfile.txt','a'); printing = '(u > min_u) = %s'; fprintf(fileID,printing, a1); fclose(fileID);
But this returns: "An argument corresponding to the conversion character 'u' in the 'formatSpec' parameter is of type 'logical'. For code generation cast this input to 'uint8', 'uint16', 'uint32' or 'uint64'."
I have tried all possible formatSpecs as in http://www.mathworks.co.uk/help/matlab/ref/fprintf.html, but I received similar errors.
Please help. Thank you.
Regards,
Biru

回答 (1 件)

Michael Haderlein
Michael Haderlein 2014 年 8 月 25 日
I think the easiest way is to write a tiny subfunction which converts a logical true and a false to the strings "true" and "false".
function str=log2str(a)
if a
str='true';
else
str='false';
end
Then, the statement is fprintf(fileID,printing,log2str(a1)); Your printing format is fine then.

カテゴリ

Help Center および File ExchangeString についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by