For loop to calculate different median in a table

2 Ansichten (letzte 30 Tage)
Mikel
Mikel am 20 Okt. 2022
Kommentiert: ag am 31 Aug. 2023
Hello,
I'm trying to write a function where I fill a table doing a median but with different values of the same cell variable. I would like to somehow automatize these so when I change my table size could make the calculations.
Right now I have a 5x5 table were I wrote all the calculation by hand:
function [PLUT]=MergeVertex(PLUT,Vp)
PLUT(1,1)=median([Vp{1,1}(1,1)]);
PLUT(2,1)=median([Vp{1,1}(2,1),Vp{2,1}(1,1)]);
PLUT(3,1)=median([Vp{3,1}(1,1),Vp{2,1}(2,1)]);
PLUT(4,1)=median([Vp{4,1}(1,1),Vp{3,1}(2,1)]);
PLUT(5,1)=median([Vp{4,1}(2,1)]);
PLUT(1,2)=median([Vp{1,1}(3,1),Vp{1,2}(1,1)]);
PLUT(2,2)=median([Vp{1,1}(4,1),Vp{2,1}(2,1),Vp{1,2}(3,1),Vp{2,2}(1,1)]);
PLUT(3,2)=median([Vp{2,1}(4,1),Vp{3,1}(3,1),Vp{2,2}(2,1),Vp{3,2}(1,1)]);
PLUT(4,2)=median([Vp{3,1}(4,1),Vp{4,1}(2,1),Vp{3,2}(3,1),Vp{4,2}(1,1)]);
PLUT(5,2)=median([Vp{4,1}(4,1),Vp{4,2}(2,1)]);
PLUT(1,3)=median([Vp{1,2}(3,1),Vp{1,3}(1,1)]);
PLUT(2,3)=median([Vp{1,2}(4,1),Vp{2,2}(3,1),Vp{1,3}(3,1),Vp{2,3}(1,1)]);
PLUT(3,3)=median([Vp{2,2}(4,1),Vp{3,2}(2,1),Vp{2,3}(2,1),Vp{3,3}(1,1)]);
PLUT(4,3)=median([Vp{3,2}(4,1),Vp{4,2}(2,1),Vp{3,3}(2,1),Vp{4,3}(1,1)]);
PLUT(5,3)=median([Vp{4,2}(4,1),Vp{4,3}(2,1)]);
PLUT(1,4)=median([Vp{1,3}(3,1),Vp{1,4}(1,1)]);
PLUT(2,4)=median([Vp{1,3}(4,1),Vp{2,4}(3,1),Vp{1,4}(3,1),Vp{2,4}(1,1)]);
PLUT(3,4)=median([Vp{2,3}(4,1),Vp{3,4}(3,1),Vp{2,4}(3,1),Vp{3,4}(1,1)]);
PLUT(4,4)=median([Vp{3,3}(4,1),Vp{4,4}(3,1),Vp{3,4}(3,1),Vp{4,4}(1,1)]);
PLUT(5,4)=median([Vp{4,3}(4,1),Vp{4,4}(2,1)]);
PLUT(1,5)=median([Vp{1,4}(3,1)]);
PLUT(2,5)=median([Vp{1,4}(4,1),Vp{2,4}(3,1)]);
PLUT(3,5)=median([Vp{2,4}(4,1),Vp{3,4}(3,1)]);
PLUT(4,5)=median([Vp{3,4}(4,1),Vp{4,4}(3,1)]);
PLUT(5,5)=median([Vp{4,4}(4,1)]);
end
I know that for that, I should do something like this, but I dont see how can I do those medians above during the loop.
Ri=5;
Rj=5;
for ii 1:length(Ri)
for jj 1:length(Rj)
PLUT(jj,ii)=median([Vp{1,1}(1,1)]);
end
end
  5 Kommentare
Mikel
Mikel am 20 Okt. 2022
Hello, thanks for helping me.
I'm working in a look up table script where the PLUT table has 25 vertexes. After some calculations I got the Vp cell matrix where every cell represents the estimation of the vertexes of all the regions that has this PLUT table (16). Each region shares with the contigous one some of the vertexes so the function that I try to build, calculates the median for every vertex estimation in the table using the data from Vp.
Sorry if I didn´t explain well, maybe an image could help. These is the table and the calculation that I do is the median among the data in each vertex.
So, in the future if want to create a table of lets say 20x20, I would like to somehow run this function for this new table.
The only reason that I created this functions is because I have a lot of code before, so I want to clean the script only having few lines for the main program. The input PLUT is an older version of the table and the output is the update of the table.
ag
ag am 31 Aug. 2023
Hi, can you please provide a mathematical representation of how you would like to choose and update the cells.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by