Effacer les filtres
Effacer les filtres

display variable value in input message

6 vues (au cours des 30 derniers jours)
Zayan Shahid
Zayan Shahid le 17 Avr 2022
Commenté : Zayan Shahid le 17 Avr 2022
I want to print the variable i and j values along with the input promt so that i can run the loop while getting the values but could not find something, tried fprintf but getting error "Error using input. The first argument to INPUT must be a string or character vector."
elements = input("Enter the number of elements: ");
i=1;
j=1;
while i<=elements
while j<=2
coordinates(i,j,1)=input(fprintf("Enter x coordinate of Element %i and node %i :",i,j));
j=j+1;
end
i=i+1;
end

Réponse acceptée

Burhan Burak AKMAN
Burhan Burak AKMAN le 17 Avr 2022
Modifié(e) : Burhan Burak AKMAN le 17 Avr 2022
You can use sprintf instead of fprintf like that.
elements = input("Enter the number of elements: ");
for i=1:elements
for j=1:2
coordinates(i,j,1)=input(sprintf("Enter x coordinate of Element %i and node %i :",i,j));
end
end

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by