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

1 回表示 (過去 30 日間)
CHEAH  YAN LING
CHEAH YAN LING 2022 年 1 月 1 日
編集済み: John D'Errico 2022 年 1 月 1 日
15
24 25 26
33 34 35 36 37

採用された回答

KSSV
KSSV 2022 年 1 月 1 日

その他の回答 (1 件)

John D'Errico
John D'Errico 2022 年 1 月 1 日
編集済み: John D'Errico 2022 年 1 月 1 日
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.

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by