【问题标题】:Find element in an array (matlab) with defined position (of time array)在具有定义位置(时间数组)的数组(matlab)中查找元素
【发布时间】:2018-03-26 12:01:58
【问题描述】:

我有一个依赖于另一个数组的数组(即,我有一个时间数组函数的张力 (V) 数组)。我想找到张力数组中某个元素在特定时刻的位置(即对应于时间向量的特定位置)。我怎样才能做到这一点?

我尝试了以下方法:

VMpzt = max(V); 
%find the maximum value of the array of tensions 
idxV = find(V == VMpzt); 
%find the corresponding index 
idxt = t(idxV);
%find the corresponding index of time vector 
diff = 0.0048377328; 
idxt2 = idxt-diff; 
%in fact, I am interested at the index of time that corresponds to this particular position 
Vmpzt = V(idxt2); %find the corresponding position of V array 

这样做,我得到错误

“数组索引必须是正整数或逻辑值。”

【问题讨论】:

  • 你能告诉我们你尝试过的向量和解决方案吗?
  • 我尝试了以下方法:VMpzt = max(V); %find the maximum value of the array of tensions idxV = find(V == VMpzt); %find the correspoding index idxt = t(idxV); %find the corresponding index of time vecotr diff = 0.0048377328; idxt2 = idxt-diff; %in fact, I am interested at the index of time that corresponds to this particular position Vmpzt = V(idxt2); %find the corresponding position of V array 这样做,我收到错误“数组索引必须是正整数或逻辑值。”

标签: arrays matlab vector time position


【解决方案1】:
idxt = t(idxV); %find the corresponding index of time vector 

此行不符合您的评论建议。它在那个索引处找到时间,而不是在索引处。然后从中减去diff 并尝试将其用作索引,但它不是索引,而是时间。我认为您的变量名称使您感到困惑。试试这个:

[V_max, V_max_index] = max(V);
t_at_v_max = t(V_max_index); %find the TIME where V was max
diff = 0.0048377328; 
t_desired = t_at_v_max - diff;

您现在需要t 等于t_desired 的索引。因为你正在处理floating point numbers,所以你不能只做find(t==t_desired),所以我们需要这样做:

t_desired_index = find(abs(t-t_desired) < diff/1000); %1000 chosen arbitrarily, you might need to change it

最后:

Vmpzt = V(t_desired_index );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    相关资源
    最近更新 更多