Convert double type string to data type
조회 수: 7 (최근 30일)
이전 댓글 표시
%These commands generate the random integers described in the problem statement. %Do not overwrite the values of X and Y in your own code. X = randi([1 10]); Y = randi([1 10]); %Enter the commands for your script mfile here. XandY = ([X, Y]) XplusY = ([X + Y])
댓글 수: 1
dpb
2020년 11월 8일
The question is totally unclear as to what you are trying to do/ask...give example of what you would want a result to be and for what purpose.
채택된 답변
Walter Roberson
2020년 11월 9일
output1 = compose('Hey, X was %g and Y was %g', X, Y);
댓글 수: 3
Walter Roberson
2020년 11월 9일
formatSpec = "The value of X is %d, and the value of Y is %d."; %notice " not '
추가 답변 (2개)
Mathieu NOE
2020년 11월 9일
hi
simply use the string() command like :
>> X = pi
X =
3.1416
>> str = string(X)
str =
"3.1416"
Mathieu NOE
2020년 11월 9일
so this is simple string concatenation and then disp (for display in command window:
X = pi
Y = 2.234
disp(['The value of X is ' num2str(X) ' and the value of Y is ' num2str(Y) ' bla bla'])
gives
The value of X is 3.1416 and the value of Y is 2.234 bla bla
댓글 수: 3
Mathieu NOE
2020년 11월 9일
XandY = X +Y;
disp(['The value of X and Y is ' num2str(XandY)])
% you can also use sprintf
% see help sprintf
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!