필터 지우기
필터 지우기

Variable in input prompt

조회 수: 11 (최근 30일)
Musaddiq Sajjad
Musaddiq Sajjad 2017년 8월 8일
댓글: Star Strider 2017년 8월 8일
I am trying to have a counter for the specific object the data of which is currently being entered.
I tried:
for n = 1:10
input_matrix(2:3,n) = input(['Enter the Mass and Volume in brackets [Mass Volume] of Object # ' n '']);
dens(n) = input_matrix(2,n) / input_matrix(3,n);
end
but it shoes a Box instead of n. Please help, thank you.

답변 (2개)

Star Strider
Star Strider 2017년 8월 8일
Use a sprintf call:
input_matrix(2:3,n) = input(sprintf('Enter the Mass and Volume in brackets [Mass Volume] of Object # %d: ', n))
  댓글 수: 2
Musaddiq Sajjad
Musaddiq Sajjad 2017년 8월 8일
Hey it works now. Thank you so much! :)
out of curiosity, why was it showing a box?
Star Strider
Star Strider 2017년 8월 8일
My pleasure!
The box is an unprintable character. That has to do with mapping ‘n’ to the ASCII character codes. If ‘n’ does not match a printable character, a box of some sort appears in its place.
If my Answer helped you solve your problem, please Accept it!

댓글을 달려면 로그인하십시오.


the cyclist
the cyclist 2017년 8월 8일
You would need to convert the number to a string to display it. Closest to your syntax would be
input(['Enter the Mass and Volume in brackets [Mass Volume] of Object #',num2str(n)])
but preferable would be
input(sprintf('Enter the Mass and Volume in brackets [Mass Volume] of Object #%d: ',n))
  댓글 수: 1
Musaddiq Sajjad
Musaddiq Sajjad 2017년 8월 8일
Thank you, the sprintf works like a charm.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Scalar Volume Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by