MATLAB找到使用min获得的值的点

时间:2014-12-01 01:06:51

标签: matlab min

我希望将时间与数组中找到的TEMP的最小值相匹配,这个数组是我从循环中的netcdf文件读取结构的(这样做了很多东西 - 不是我不想摆脱循环)。我有snctools,这就是我用于netcdfs的东西。

这是我目前相关的代码行:

%Get the netcdf file with file_string loading into MATLAB
nc=netcdf(file_string);
%Work out the number of files I need to loop through
[files]=dir('*.nc');
max1=length(files);

for d1=1:max1
%extract the TEMP 1-D array
B1=nc{'TEMP'}(:)
%assign to value
dat.TEMP_min(d1)= min(B1);
end

现在有另一个相同长度的变量称为' TIMES'。如果min(B1)= 10.5并且是B1的第n个元素,那么我想找到TIMES的第n个元素并将其保存为dat.TEMP_min_TIME。我该怎么做呢?

请提供足够的注释,以便新手能够理解。

1 个答案:

答案 0 :(得分:0)

你可以在你的循环中使用(抱歉伪代码,不确定你对n和TIMES的定义)

[M,I] = min(B1);
dat.TEMP_min(d1)= M;
if (I == n)
   dat.TEMP_min_TIME = nc1{'TIMES'}(I); %
end