How to create 15,24 25 26,33 34 35 36 37 in a triangle pattern?
1 次查看(过去 30 天)
显示 更早的评论
15
24 25 26
33 34 35 36 37
0 个评论
采纳的回答
更多回答(1 个)
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))
Or, you might try a variant of this:
disp(string(24) + " " + string(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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!