Replace values in a array

6 次查看(过去 30 天)
Miguel Albuquerque
Miguel Albuquerque 2022-7-20
Hey to all, thanks in advance
Is there a way of: for each row of distance_matrix, for the values that are not zero,find the most aproximate values in the array range with those of that row in distance_matrix. Once we identified in which column the values are most similar to those in the row of distance_matrix, replace those values in range by the values present in each row of RMC2.
Thank you
  8 个评论
dpb
dpb 2022-7-20
That does what you asked for...I'm not trying to decipher/debug yours...
Miguel Albuquerque
Miguel Albuquerque 2022-7-20
done
distance_matrix=round(distance_matrix);
range=round(range);
RMC2=round(RMC2);
for i =1:size(RMC2,1)
thisrow=RMC2(i,:)
thisrow2=distance_matrix(i,:)
isR2=find(thisrow2)
thisrow2=distance_matrix(i,isR2)
[val,pos]=intersect(range,thisrow2)
pos=pos.';
first_element=pos(1,1)
last_element=pos(1,end)
value=(last_element-first_element)+1
thisrow=RMC2(i,(1:value))
range(1,(first_element:last_element))=thisrow
end

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by