Programming Practices Tips - Index on matrix with some information

3 views (last 30 days)
Hi,
I want a tip on what is the best way to code something. I have a matrix with some information. The first column is the index number and the other columns are the informations (length, area, mass etc).
I would like to know if it is best to keep the first column or not. I mean, the index number is the number of row, so, instead of looking for the index number in the matrix and returning the proper information of the other columns, I just need to get the information on that row. However, I was told I could keep the index numbers because if I change my input, I don't need to rewrite the input, but I will have to look for the index number in the matrix.
Which one is the best? Keep the index numbers and do the research every time or use the rows numbers to find the information?
Thanks

Accepted Answer

Jan
Jan on 6 Mar 2015
There is no "best" way.
Using the row index of the array directly avoid redundant information. Redundant information waste resources, so avoiding this is an important strategy.
If the format is changed in the future, adding this additional column is not too complicated.
You could keep this clean by using a dedicated subfunction to search for an index. Then there is only one place, where changes have to be implemented.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!