How to create 15,24 25 26,33 34 35 36 37 in a triangle pattern?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
CHEAH YAN LING
el 1 de En. de 2022
Editada: John D'Errico
el 1 de En. de 2022
15
24 25 26
33 34 35 36 37
0 comentarios
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 1 de En. de 2022
Editada: John D'Errico
el 1 de En. de 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))
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 comentarios
Ver también
Categorías
Más información sobre Numeric Types en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!