Re: [讨论] function的intput如何为字串&字符

楼主: celestialgod (天)   2015-10-20 01:07:53
※ 引述《Souseasou3 (Almighty)》之铭言:
: 如题
: 最近遇到几个问题,让我迫切想知道如何让function的intput为字串字符
: ex:
: 1.)
: 此function为输入欲知的罗马数字符号,然后output为所对应的数字
: 如 input=I output=1 ; intput=II output=2 ......
: 最接近的作法为intput函数,但我想知道有办法直接在这个function的intput直接输入字
: 串&字符?
看不懂你在写什么...不是本来就可以输入字串了吗= =
function out = feedback(in)
out = in;
end
feedback('in1') % 'in1'
你如果说的是这种:
function out_opts = structMapping(varargin)
option_default = struct('in1', 5, 'in2', 10);
optsCell = [fieldnames(option_default), struct2cell(option_default)];
optionsReplace = reshape(varargin, 2, [])';
[loc2,loc1] = ismember(optionsReplace(:,1), fieldnames(option_default));
optsCell(loc1(loc1~=0), 2) = optionsReplace(loc2, 2);
out_opts = cell2struct(optsCell(:, 2), optsCell(:,1));
end
structMapping('in1', 7)
output:
1 x 1 struct:
in1: 7
in2: 10
structMapping('in1', 7, 'in2', -7)
output:
1 x 1 struct:
in1: 7
in2: -7
还是这种
function out = returnInputName(in)
out = inputname(1);
end
SSS = 1;
returnInputName(SSS) % 'SSS'
: 2.)
: 如何写一个function,其intput为输入圆的 中心 半径 颜色
: 然后此function就会依照对应数据plot出这个圆
: 但如何在在圆的intput输入字符(颜色)呢?
: p.s. r 为红色 b 为蓝色 ......
: 麻烦高手求解?
function [] = plotCircle(origin, r, col)
theta = linspace(0, 2*pi);
plot(r*cos(theta) + origin(1), r*sin(theta) + origin(2), 'Color', col);
end
plotCircle([0, 0], 5, 'r')
Or you can use anonymous function
plotCircle = @(x0, y0, r, col) plot(r*cos(linspace(0,2*pi)) + x0, ...
r*sin(linspace(0,2*pi)) + y0, 'Color', col);
plotCircle(0, 0, 5, 'r')
补充一点 画圆记得设定 axis square 以保证两轴等长看起来是圆

Links booklink

Contact Us: admin [ a t ] ucptt.com