Message Boards Message Boards

0
|
3616 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

[?] Use a row matrix as an input for Switch function?

Posted 7 years ago

Hi Friends, I am trying to use Switch function for a programming problem. Having a large number of condition/value sets coming from a previous calculations, I can not write them manually in "Switch" function, though they are present in a row matrix form. How can import this matrix to switch function so that it can work smoothly ? I have already tried the functions like Grid, Flatten, Sequence etc., nothing seems to work. Will appreciate any suggestion. Attached is the *nb file having a small example of this problem. Thanks

What I have -

Matrix = {Condition1, Value1, Condition2, Value2, Condition3, Value3, ........... , Condition30, Value30}

What i want -

Function ABCD which can be used with switch function as -

Switch[expression, ABCD[Matrix]]

to give similar o/p as -

Switch[expression, Condition1, Value1, Condition2, Value2, Condition3, Value3, .... ]

Attachments:
POSTED BY: S G

Hi, Switch has Holdrest as attribute. You could perhaps add the 4 that you used in your matrix in the first column. Then use Sequence so this will be evaluated.

Matrix = {4, 3, Odd, 4, Even};
Switch[ Sequence @@ Matrix]
POSTED BY: l van Veen
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract