Variable in input prompt
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (2)
Star Strider
am 8 Aug. 2017
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 Kommentare
Star Strider
am 8 Aug. 2017
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
am 8 Aug. 2017
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))
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!