For loop to calculate different median in a table
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
ag
am 31 Aug. 2023
Hi, can you please provide a mathematical representation of how you would like to choose and update the cells.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!