フィルターのクリア

update a string function in matlab

3 ビュー (過去 30 日間)
ali hassan
ali hassan 2022 年 1 月 31 日
コメント済み: ali hassan 2022 年 1 月 31 日
i am using sprintf to generate a message but how can i get a string 'and' in my message between 4 and 5 which is vector b
a=5;b=[4 5];
warningmessage=sprintf('it has happened ''%s'' times in the flight in the ''%s'' second',num2str(a),num2str(b));
uiwait(warndlg(warningmessage,'EGT error'))

採用された回答

Stephen23
Stephen23 2022 年 1 月 31 日
a = 5;
b = [4,5];
sprintf('it has happened %d times in the flight, in the %d and %d second',a,b(1),b(2))
ans = 'it has happened 5 times in the flight, in the 4 and 5 second'
A general solution:
tmp = compose('%d',b);
tmp(2,:) = {', '};
tmp{2,end-1} = ' and ';
sprintf('it has happened %d times in the flight, in the %s second',a,[tmp{1:end-1}])
ans = 'it has happened 5 times in the flight, in the 4 and 5 second'
  1 件のコメント
ali hassan
ali hassan 2022 年 1 月 31 日
can you please explain the general solution?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGuidance, Navigation, and Control (GNC) についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by