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 CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by