Effacer les filtres
Effacer les filtres

output for different changing variables

4 vues (au cours des 30 derniers jours)
Jay Hanuman
Jay Hanuman le 29 Déc 2016
Commenté : Jay Hanuman le 30 Déc 2016
I have 4 variables a,b,c,d. a can vary 1,2 i.e. a=1,2, b=1,2,3, c=1,2,3,4, d=1,2,3,4,5 so by varying each element I want to make output value i.e.
a b c d output
1 1 1 1 1
1 1 1 2 2
1 1 1 3 3
1 1 1 4 4
1 1 1 5 5
now varying c with 1 value and d with all values i.e.
a b c d output
1 1 2 1 6
1 1 2 2 7
1 1 2 3 8
1 1 2 4 9
1 1 2 5 10
now change c to 3 and doing above so getting output as 11,12,13,14,15. when c reaches max varying limit then change b i.e.
a b c d output
1 2 1 1 16
1 2 1 2 17
1 2 1 3 18
1 2 1 4 19
1 2 1 5 20
then
a b c d output
1 2 2 1 21
1 2 2 2 22
1 2 2 3 23
1 2 2 4 24
1 2 2 5 25
so like this I want to proceed and want output for all conditions of a,b,c,d. so how to do it or any equation to do this in matlab. in above a,b,c,d vary 2,3,4,5 i.e in increasing order but in general case they can vary without increasing order e.g. a,b,c,d can vary 7,4,9,13.
I have inputs and want to know how to get output for particular input. i.e. if inputs a,b,c,d are given below then how to get output as below
a b c d output
1 1 1 1 1
1 1 1 2 2
1 1 1 3 3
1 1 1 4 4
1 1 1 5 5
or
another way I have attached file then for particular inputs how to fetch particular number to make output. i.e.
a b c d output
1 1 1 1 1
1 1 1 2 2
1 1 1 3 3
1 1 1 4 4
1 1 1 5 5

Réponse acceptée

Matt J
Matt J le 29 Déc 2016
[d,c,b,a]=ndgrid(1:5,1:4,1:3,1:2);
a=a(:); b=b(:); c=c(:); d=d(:);
  3 commentaires
Matt J
Matt J le 29 Déc 2016
output=sub2ind([5 4 3 2] ,d,c,b,a)
Jay Hanuman
Jay Hanuman le 30 Déc 2016
Thanks works

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Adding custom doc 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