Effacer les filtres
Effacer les filtres

simple combinations between cells

1 vue (au cours des 30 derniers jours)
Riccardo Tronconi
Riccardo Tronconi le 20 Juil 2021
Dear guys I'm looking for calculating the simple combinations between 3 cell:
T{1}=
Column 1 Column 2
3.29468361984674 3.24793763967276
3.25488582798159 3.33467494150750
3.30016433354633 3.30779418978228
3.36715866345752 3.17459467737618
3.42871475496273 3.18335187435669
3.30662100520200 3.16100391098778
T{2}=
Column 1 Column 2
2.69361371618303 3.57755708771298
2.56422065002361 3.57364773072377
2.66103273449339 3.54110582681669
2.60486706822838 3.55023611776072
2.60797207622599 3.58518248687590
2.65230479016750 3.50848441872052
T{3}=
Column 1 Column 2
3.12870601260590 4.33208439890896
3.14007960123577 4.37853754127380
3.03522738819268 4.35174951763305
3.16142049026022 4.28790024805517
2.98099119386563 4.05129787027474
2.97887698391243 4.28015976006215
Since the simple combinations are 3. I'm looking for
S{1}= [T{1} T{2}]
S{2}= [T{2} T{3}]
S{3}= [T{3} T{1}]
How to do that without a for loop?

Réponse acceptée

Rik
Rik le 20 Juil 2021
Modifié(e) : Rik le 20 Juil 2021
It can probably be done without a loop, but why do you want that? Loops are very efficient (as long as there isn't a builtin vectorized alternative).
T={1,2,3};
ind_list=nchoosek(1:numel(T),2)
ind_list = 3×2
1 2 1 3 2 3
This is not the order you want, so we will need to use something else:
ind_list=(1:numel(T)).'+(0:1);
ind_list=mod(ind_list,numel(T));
ind_list(ind_list==0)=numel(T);
ind_list
ind_list = 3×2
1 2 2 3 3 1
Now we can loop through the rows of ind_list to create S:
S=cell(size(ind_list,1),1);
for n=1:size(ind_list,1)
tmp=T(ind_list(n,:));
tmp=horzcat(tmp{:});
S{n}=tmp;
end
S
S = 3×1 cell array
{[1 2]} {[2 3]} {[3 1]}
  1 commentaire
Riccardo Tronconi
Riccardo Tronconi le 20 Juil 2021
thank you very much!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by