當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Matlab AMPL DataFrame.getRow用法及代碼示例

classmethod DataFrame.getRow()

用法

[行] = getRow({rowindices})

[行] = getRowByIndex(index)

說明

[row] = getRow({rowindices}) 獲取由 rowindices 指示的行

[row] = getRowByIndex(index) 獲取指定的從零開始的索引指定的行

輸入參數

rowindices 索引值的元胞數組,基數 DataFrame.getNumIndices

index 所需行的從零開始的整數索引

輸出參數

row 包含DataFrame 的水平“slice” 的元胞數組

示例

通過指定索引及其在表中的序號來提取行

df = DataFrame(3, 'ORIGIN', 'DEST', 'MODE', 'time');
origins = {'London'; 'New York'; 'Milan'; 'London'; 'New York'; 'Milan'}
destinations = {'New York'; 'Milan'; 'London'; 'New York'; 'Milan'; 'London'}
df.setColumn('ORIGIN', origins);
df.setColumn('DEST', destinations);
df.setColumn('MODE', {'air';'air';'air'; 'normal';'normal';'normal'})
df.setColumn('time', [6,7,2,60,60,20]);
% The two statements below refer to the same row
row1 = df.getRow('London', 'New York', 'air');
row2 = df.getRowByIndex(1);

row1(4)
row2(4)

給出:

ans =
  6
ans =
  6

相關用法


注:本文由純淨天空篩選整理自ampl.com大神的英文原創作品 getRow。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。