How do you get a variable to recognized in function
Everytime I run this function it say D is not recognized
GetUserInput();
filename = [‘ENGR131_Lab4_CatMap_’, D];
load(filename, ‘-mat’);
PlotMap(C,D)
% B
function [C,D]=GetUserInput()
W = [‘A’, ‘B’];
X = [‘b’, ‘r’, ‘m’, ‘c’, ‘y’, ‘g’];
C = ”;
D = ”;
for i=1:2
switch i
case 1
%unable to get it too work without error W=options
prompt = ‘Enter head marker body color (b, r, m, c, y, g): ‘
case 2
%unable to get it too work without error X=options
prompt1 = ‘File (A,B): ‘
for I=1:2
if I == 1
while true
C = input(prompt, ‘s’);
if any(C == X)
break;
end
end
else I == 2
while true
D = input(prompt1, ‘s’);
if any(D == W)
break;
end
end
end
end
end
end
endEverytime I run this function it say D is not recognized
GetUserInput();
filename = [‘ENGR131_Lab4_CatMap_’, D];
load(filename, ‘-mat’);
PlotMap(C,D)
% B
function [C,D]=GetUserInput()
W = [‘A’, ‘B’];
X = [‘b’, ‘r’, ‘m’, ‘c’, ‘y’, ‘g’];
C = ”;
D = ”;
for i=1:2
switch i
case 1
%unable to get it too work without error W=options
prompt = ‘Enter head marker body color (b, r, m, c, y, g): ‘
case 2
%unable to get it too work without error X=options
prompt1 = ‘File (A,B): ‘
for I=1:2
if I == 1
while true
C = input(prompt, ‘s’);
if any(C == X)
break;
end
end
else I == 2
while true
D = input(prompt1, ‘s’);
if any(D == W)
break;
end
end
end
end
end
end
end Everytime I run this function it say D is not recognized
GetUserInput();
filename = [‘ENGR131_Lab4_CatMap_’, D];
load(filename, ‘-mat’);
PlotMap(C,D)
% B
function [C,D]=GetUserInput()
W = [‘A’, ‘B’];
X = [‘b’, ‘r’, ‘m’, ‘c’, ‘y’, ‘g’];
C = ”;
D = ”;
for i=1:2
switch i
case 1
%unable to get it too work without error W=options
prompt = ‘Enter head marker body color (b, r, m, c, y, g): ‘
case 2
%unable to get it too work without error X=options
prompt1 = ‘File (A,B): ‘
for I=1:2
if I == 1
while true
C = input(prompt, ‘s’);
if any(C == X)
break;
end
end
else I == 2
while true
D = input(prompt1, ‘s’);
if any(D == W)
break;
end
end
end
end
end
end
end loop, errorchecking, selection statement MATLAB Answers — New Questions