|
From: | Harishkumar U |
Subject: | Re: Multiple case function error |
Date: | Sun, 5 Apr 2020 09:41:00 +0530 |
Thanks for the tip!! Will use otherwise and see.
On Sat, Apr 4, 2020, 12:52 PM Harishkumar U <address@hidden> wrote:Thanks for the feedback!This is what I am trying to achieve, this is a sample test code for a case operationA = [3 4 5; 7 2 6; 8 1 9];
d = A(1,1);
g = A(2,1);
y = input('enter a value: ');
switch (y)
case d
xpos = [A(1,3) A(2,2) A(3,1)]
xneg = [A(3,1) A(2,2) A(1,3)]
case g
xxpos = [A(1,1) A(2,1) A(2,2)]
xxneg = [A(1,1) A(2,1) A(2,2)]
endswitch
z = input('enter a different value: ');
switch (z)
case {xpos, xxpos}
r = A(2,2)+A(2,1)
case {xneg, xxneg}
n = A(3,1)+A(2,1)
endswitchAfter displaying the results of first switch, I would like to use a different switch whose values are in the range xpos or xxpos it should perform one operation then ifthe value is in range of xneg or xxneg it should perform another operation. But since we either chose one case the other case value is not invoked to it throws an error like thisenter a different value: 5
error: 'xxpos' undefined near line 19 column 19
error: called from
nabbleuserJamessherman at line 18 column 5Again, for those reading the mailing list, please use bottom posting.so you start off with d and g defined by two values from A, so d=3 and g=5Then you ask the user to put in a value. If they enter a 3, you assign one combination of A elements to xpos and xneg. If they enter 5, a different assortment of A elements get assigned to xxpps and xxneg.Next, if they enter a value that was assigned to xpos or xxpos, you want it to evaluate r, if it was a value assigned to xneg or xxneg, you want it to evaluate nHow can it evaluate xpos, xxpos xneg or xxneg if you never define it?Why do you use separate x and xx variables? Why not just have it assign to xpos and xneg in the first switch statement? The assignment will change depending in your switch, but the variable names will be consistent.What happens if someone enters 2 in the first switch? In that case neither Haas been defined and the second switch will break. You probably want an 'otherwise' statement in each switch.
[Prev in Thread] | Current Thread | [Next in Thread] |