How can I replace a pair of coordinates (x;y) in a table by values from a list of reference coordinates?

2 次查看(过去 30 天)
Hi,
I need your help to create a short script.
I have two series of data in Excel with pixel coordinate one for x and one for y, in two columns, for all existing spots counted in every location of a sample.
I aslo have some reference values selected for every unique pair of coordinates also (X;Z) in two columns, plus two extra columns for the corresponding absolute position on the sample (Abs_Len) and the relative position (Rel_Len).
I would like to create a new matrix of two columns that replace every pair of x;y by the corresponding Abs_Len and Rel_Len according to the reference columns X;Y.
Thansk for your help

采纳的回答

Antoni Garcia-Herreros
Hello Mathieu,
You can try something like this:
However, I did not find any X, Y pair of values present in both len and IHC.
clear all
close all
len = readmatrix('SAMPL01_R.xlsx','Sheet','len');
IHC = readmatrix('SAMPL01_R.xlsx','Sheet','IHC');
OHC = readmatrix('SAMPL01_R.xlsx','Sheet','OHC');
for i=1:size(len,1)
x=len(i,3); % X value in len
y=len(i,4); % Y value in len
fIHC=find(ismember(IHC(:,3:4),[x,y],'rows')); % Find the indices where IHC is equal to X and Y
fOHC=find(ismember(OHC(:,3:4),[x,y],'rows')); % Find the indices where O is equal to X and Y
if ~isempty(fIHC)
for j=1:length(fIHC) % Loop through IHC indices
IHC(fIHC(j),5:6)=len(i,5:6); % Add len_mume and len_rel to IHC
end
end
if ~isempty(fOHC)
for j=1:length(fOHC) % Loop through OHC indices
OHC(fOHC(j),5:6)=len(i,5:6); % Add len_mume and len_rel to OHC
end
end
end
OHCMat=OHC(OHC(:,5)>0,:); % Create the matrix with only the matching values
IHCMat=IHC(IHC(:,5)>0,:);
Let me know if that helps,
  2 个评论
Mathieu Petremann
Mathieu Petremann 2023-4-12
Hello Antoni,
Thanks a lot. Indeed the file I sent was not the best exemple.
But I will try the script tomorrow with other files.
That should still help me a lot!
I will let you know.
Best,
Mathieu

请先登录,再进行评论。

更多回答(1 个)

Mathieu Petremann
Mathieu Petremann 2023-4-12
Hi,
Here is the file.
The len sheet is my reference table and I want to attribute the refence len_mume and len_rel to the IHC and OHC sheets for the corresponding coordinates.
Thanks!

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by