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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by