フィルターのクリア

Beginning Matlab simple text question

2 ビュー (過去 30 日間)
cassie
cassie 2014 年 5 月 5 日
コメント済み: cassie 2014 年 5 月 5 日
I am using a textbox that will display updating information on a simple force calculator and I need to know what to add to this code to display the units at the end of the string (Newtons in this case). Thank you!
set(h,'string',num2str(ForceB)); %will display Force in Newtons

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 5 月 5 日
You can use the square brackets to concatenate two strings (or arrays, matrices, etc.) together. For example:
a = 'hello';
b = ' world';
c = [a b]; % c is the concatenation of a and b: 'hello world'
You just have to enclose your num2str in these square brackets and add the string for the units, similar to the above example.
  1 件のコメント
cassie
cassie 2014 年 5 月 5 日
This worked, Thank you!
h=findobj('tag','force_b'); a=' N'; set(h,'string',[num2str(ForceB),a]);

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 5 月 5 日
Try this:
% Create a string from the number, and append the word Newtons.
str = sprintf('%.3f Newtons', ForceB);
% Send the string to the static text label control.
set(h,'String',str); % Will display Force in Newtons

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by