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일

0 개 추천

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일

1 개 추천

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

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2014년 5월 5일

댓글:

2014년 5월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by