# How to generalize code with many cases (Matlab)

2 vues (au cours des 30 derniers jours)
Afluo Raoual le 16 Mar 2021
Commenté : Afluo Raoual le 16 Mar 2021
Dear members;
I have this Matlab code
for ess=1:n % 'n' is the number of cases (here n=4)
switch ess
case 1
Hc=H(1:T,:);
V=VV(1:20);
case 2
Hc=H(T:end,:);
V=VV(11:30);
case 3
Hc=H(T:end,:);
V=VV(21:40);
case 4
Hc=H(T:end,:);
V=VV(31:50);
end
end
Here I have just 4 cases. The first case stay as it is and the other cases will take 20 bits of VV each time. So if I have many cases more than 100 for example. How can I generalize this part of program in order to work with any number of cases.
Thank you.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Jan le 16 Mar 2021
Modifié(e) : Jan le 16 Mar 2021
for ess = 1:n
if ess == 1
Hc = H(1:T,:);
else
Hc = H(T:end,:);
end
k = (ess - 1) * 10 + 1;
V = VV(k:k + 19);
end
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Afluo Raoual le 16 Mar 2021
Thank you for your help as usual Sir.
I appreciate it

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Get Started with MATLAB 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