This is what I have done now
x = {d = 3, e = 4, f = 5};
a = {g = 7, h = 2, i = 6};
b = {k = 8, l = 1, m = 9};
d = x(1,1);
e = x(1,2);
f = x(1,3);
g = a(1,1);
h = a(1,2);
i = a(1,3);
k = b(1,1);
i = b(1,2);
m = b(1,3);
y = input('enter a value: ');
switch(y)
case d
xpos ={d, h, m};
xneg ={k, h, f};
ss = input('enter cross value: ');
case g
xxpos = {g, h, d};
xxneg = {f, i, e};
ss = input('enter cross value: ');
endswitch
if (ss = xpos && xxpos)
max = d+h;
disp(max)
else
min = g-f;
disp(min)
endif
but now, I am getting these errors
enter a value: d
enter cross value: h
error: invalid conversion from cell array to logical value
error: called from
crossminmax at line 32 column 1
enter a value: d
error: binary operator '==' not implemented for 'cell' by 'scalar' operations
error: called from
crossminmax at line 16 column 1
Thank you! I changed cross variable name. Yes, switch y block input should match the output of cross block to obtain either xpos or xneg value. But, when I use 'd' its ignoring the case statement and skipping forward. Can I use If else condition? something similar to switch case statement though
On Thu, Apr 2, 2020 at 2:14 AM Nicholas Jankowski <
address@hidden> wrote:
Hi,
I am trying to use multiple cases for a math operation using case{..,..} as
per octave reference. But unfortunately I am getting an error
'enter a value: d
enter cross value: h
error: 'xxpos' undefined near line 24 column 13
error: called from
crossminmax at line 22 column 1'
I've had some trouble even trying to recreate your error.
1 - did you define some values for d, etc, outside of what you showed? because if I run your script from a clean workspace i get:
enter a value: d
error: 'd' undefined near line 1 column 1
error: called from
casetest at line 3 column 3
i notice some other things. You use cross as a variable name, but it is the name of a function for performing a vector cross product. so if the first switch doesn't set a value to overwrite the meaning of cross, you get an error calling the switch(cross) line.
do you mean for your switch(y) block to match the letter input d or g? in that case you need it to be defined as a character with quotation marks, 'd', or "d". Of course, then it's not clear what values will be going into xpos or xxpos.
look at the help for switch with: >> help switch
--
![]()
Harish KumarM: +91 9488309620, Whatsapp: +91 9944308505
E: address@hidden
A:15/36, Ramanna Layout 2, Bharathi Park Road 2,
Saibaba Colony, Coimbatore -641 043. Tamil Nadu, India
![]()