在我的代碼中,我正在處理一組度量(一個float的向量),其中每個元素都有兩個相關的不確定性(比如+上/下)。 比方說,我想傾倒在屏幕上這些數值,像矢量對或矢量對?
Loop over the vector of the measurements
{
cout << i-th central value << " +" << i-th up uncertainty << "/-" << i-th down uncertainty << end;
}
什麼是最有效的/優雅的方式來做到這一點?
1)使用一對矢量
vector<float> central; //central measurement
pair<vector<float>, vector<float>> errors; //errors
for(int i = 0; i < central.size ; i++)
{
cout << central.at(i) << " +" << errors.first.at(i) << "/-" << errors.second.at(i) << endl;
}
2)使用對載體的:
vector<float> central; //central measurement
vector<pair<float,float>> errors; //errors
for(int i = 0; i < central.size ; i++)
{
cout << central.at(i) << " +" << errors.at(i).first << "/-" << errors.at(i).second << endl;
}
3)兩個獨立的載體:
vector<float> central; //central measurement
vector<float> errUp; //errors up
vector<float> errDown; //errors down
for(int i = 0; i < central.size ; i++)
{
cout << central.at(i) << " +" << errUp.at(i) << "/-" << errDown.at(i) << endl;
}
使'struct'包含所有三個數據。 – andre