我正试图从表中找到最小值。如何从.txt
文件的多列中找到最小值
TheTable = importdata('myfile.txt')
TheYear = TheTable(:,1);
ColumnsWithValues = TheTable(2:13);
MininumValue = min(TheTable(Year > 2010 & Year < 1920)) ' This is only reading the first column
.txt文件看起来像:
2009 -2 -3 3 5 7 8 10 9 7 4 3 5
2010 -1 -4 3 5 7 6 6 9 11 5 5 4
2011
...
...
2020
2021 ....
2022 ....
添加列索引器2:end
以获取年后的列。对于样本数据,如果我们使用TheYear > 1920 & TheYear < 2011
,这是输出:
MinimumValue = min(TheTable(TheYear > 1920 & TheYear < 2011, 2:end))
% MinimumValue =
%
% -2 -4 3 5 7 6 6 9 7 4 3 4
要减少到单个min
值,请使用"all"标志:
MinimumValue = min(TheTable(TheYear < 2011 & TheYear > 1920, 2:end), [], 'all')
% MinimumValue =
%
% -4