How to create 15,24 25 26,33 34 35 36 37 in a triangle pattern?

1 vue (au cours des 30 derniers jours)
CHEAH  YAN LING
CHEAH YAN LING le 1 Jan 2022
15
24 25 26
33 34 35 36 37

Réponse acceptée

KSSV
KSSV le 1 Jan 2022

Plus de réponses (1)

John D'Errico
John D'Errico le 1 Jan 2022
Modifié(e) : John D'Errico le 1 Jan 2022
You cannot create an array that does not have the same number of elements in each row. MATLAB does not allow this. Yes, you could write your own special class of objects that would do so. Then you would need to write your own functions to do anything you need to do with them. That would include subscripting, and displaying the objects. Expect this to take some effort, at least if you don't have experience in writing tools like that.
Can you write out each line separately in the command window? Well, yes. Now you will need to format it properly, to offset the first and second rows by an appropriate amount. And I'm sorry, but I don't do homework for students.
Could you do this using strings? Again, yes. Now you would convert each number into its character representation. A tool like num2str would help you there.
disp(num2str(15))
15
Or, you might try a variant of this:
disp(string(24) + " " + string(25))
24 25
As you see, you could build up a vector that contains just the numbers you want as characters. Having done that, now do the same thing for each row. If you are careful, you could build an entire character array like that.

Catégories

En savoir plus sur Numeric Types 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