Effacer les filtres
Effacer les filtres

How to display variables within a full sentence without using a char array or strings?

7 vues (au cours des 30 derniers jours)
Paul
Paul le 3 Mar 2023
Commenté : Cameron le 3 Mar 2023
One way I was looking to do it was:
disp("The original number was "+integer+" and the flipped number is "+flipped)
where integer and flipped are variables that have values assigned to them. That does output text, but I don't know if that is considered an array or string. Still pretty new to this, but having a blast :D

Réponses (1)

the cyclist
the cyclist le 3 Mar 2023
Modifié(e) : the cyclist le 3 Mar 2023
I would recommend fprintf
num1 = 15;
num2 = 51;
fprintf("The original number was %d and the flipped number is %d",num1,num2)
The original number was 15 and the flipped number is 51
The syntax of this more powerful command can be a bit trickier to learn, but it will be worth it in the long run.
  1 commentaire
Cameron
Cameron le 3 Mar 2023
num1 = 15;
fprintf("The original number was %s and the flipped number is %s",string(num1),flip(char(string(num1))))
The original number was 15 and the flipped number is 51

Connectez-vous pour commenter.

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by