Programming Practices Tips - Index on matrix with some information

3 ビュー (過去 30 日間)
Thales
Thales 2015 年 3 月 6 日
回答済み: Jan 2015 年 3 月 6 日
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

採用された回答

Jan
Jan 2015 年 3 月 6 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by