how to tell matlab in a matrix that if my program does not assign value to an element do not fill it with 0?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Erwin Avendaño
am 2 Nov. 2017
Bearbeitet: Stephen23
am 3 Nov. 2017
I'm doing a program in matlab with the gui, which is gauss jordan at the beginning my program is asking for the elements of the matrix but my program can store up to 5x6 then when you enter a 2x3 matrix the others fill it with 0 which I get an error when it comes to giving me results How can I tell him not to fill it with 0?
3 Kommentare
Akzeptierte Antwort
Erwin Avendaño
am 3 Nov. 2017
Bearbeitet: Stephen23
am 3 Nov. 2017
1 Kommentar
Stephen23
am 3 Nov. 2017
Bearbeitet: Stephen23
am 3 Nov. 2017
All of those individually numbered fieldnames make your code much more complex than it needs to be. Just use an array and indexing to make your code much simpler, more versatile, and less buggy.
Any time that you find yourself copy-and-pasting code with just minor changes then you really need to reconsider your code design.
Weitere Antworten (1)
Walter Roberson
am 2 Nov. 2017
Bearbeitet: Walter Roberson
am 2 Nov. 2017
There are some ways to prevent a matrix from zero filling as it is extended:
- Do not extend it. Assign it full size at the beginning, and put in some non-zero value for the unused space. For example initialize as nan(3,4)
- If you must extend it, then at each point where it might be extended, check if you are extending it, and carefully assign some non-zero value for the extension areas that are not to be zero filled.
- Instead of using a numeric array, use a cell array initialized to empty arrays until it is completely filled out. You might need to write code to display intermediate results.
2 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!