What is a parameter and what is a counter in MATLAB?

36 次查看(过去 30 天)
So I'm confused as to what exactly a parameter is... is it any input or output value? Also, I am unsure as to what a counter is, is it a variable i used to increment by a certain number? ex: i = 0 %initialized counter% then later in the algorithm for bracketing it becomes i <--- i + 1?

回答(3 个)

Azzi Abdelmalek
Azzi Abdelmalek 2016-8-12
Parameters are in general constants defining different kind of object. For example when you define a polynomial p=5*x^2+2*x+10 you need to provide the vector [5 2 10] which is considered as a parameter, x is considered as a variable. But Matlab doesn't see the difference between what you consider a variable or a parameter, they are all seen as a variable. Matlab Uses a notion of parameter in Simulink blocks, whre each block has its own parameter that you can access or modify with the functions get_parm and set_param.
A counter is simply a variable that you increment, and it's not seen by Matlab as a special variable,

Image Analyst
Image Analyst 2016-8-12
A parameter is a variable. usually it is something that divides or multiplies some other expression, but could be other things, like the order of a polynomial that you want to fit, or whatever. It may be passed into a function via the input argument list, and it may also be passed out.
A counter is something that counts an event in a loop. In your example they chose (the bad) name i for the counter, and probably in the loop increment it when something happens. For example, it could be incremented every time some function is successful, or whatever
i = 0; % Initialize to zero because no files have been processed yet.
for k = 1 : 100
success = DoSomething(filenames{k}); % Process the kth file.
if success
i = i + 1;
end
end

Star Strider
Star Strider 2016-8-12
Parameter: A parameter is a characteristic value of a system. In the simplest terms, in the linear equation:
y = m*x + b;
or equivalently:
y = p(1)*x + p(2);
the values for ‘m’ and ‘b’, or equivalently the parameter vector ‘p=[p(1) p(2)]’, are parameters that determine the line the equation describes. Parameters are treated as constants, and while it is occasionally necessary to change them, they are generally not considered to be variables.
The input or output question is a bit more difficult to describe and depends on the context. In this anonymous function:
y = @(p,x) p(1).*x + p(2);
they are input arguments.
If you want to find the parameter values of a function that minimise that function, for example finding the parameters that most closely approximate the data with this equation:
yfit = @(p,x) p(1).*x.^2 + p(2).*x + p(3);
with
x = -5:5;
y = randi(9, 1, numel(x));
S = @(p) sum((yfit(p,x) - y).^2);
P = fminsearch(S, [0.5; 2; 5]);
(the estimated parameters are the ‘P’ vector), they are outputs of fminsearch. Here, they are the best fit values for ‘p’ that most closely approximate the function output and the dependent variables.
So, it depends on what you’re doing.
Counter: You’re correct on the definition of ‘counter’. It is a variable that simply increments (or decrements) by a specific ‘step’ value in every iteration of a loop. A for loop initialises and changes it automatically. You have to code it yourself in a while loop.
I’ve done my best to make this a s straightforward as I can. I very much hope I did not add to your confusion.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by