Is it possible to iterate over a list of functions in MATLAB? I'm trying to test different radial basis functions and this seems like the best way to do it.
Note that Matlab iterates through the columns of list , so if list is a nx1 vector, you may want to transpose it. If you don't know whether list is a column or a row vector, you can use the rather ugly combination (:)' : for elm = list(:)'; %... ;end .
Description: The percent sign is most commonly used to indicate nonexecutable text within the body of a program. This text is normally used to include comments in your code. Some functions also interpret the percent sign as a conversion specifier.
Use the up-arrow key, followed by the enter or return key, to iterate, or repeatedly execute, this statement: x = sqrt(1 + x) Here is what you get when you start with x = 3. These values are 3, / 1 + 3, √ 1 + / 1 + 3, √ 1 + √ 1 + / 1+3, and so on.
Basically there is no do while loop in Matlab like c programming, cpp programming, and other programming languages. But instead of using do while loop works powerfully in Matlab.
You can make a cell array of function handles and iterate over that. For example:
vec = 1:5; % A sample vector of values
fcnList = {@max, @min, @mean}; % Functions to apply to the vector
nFcns = numel(fcnList); % Number of functions to evaluate
result = zeros(1, nFcns); % Variable to store the results
for iFcn = 1:nFcns
result(iFcn) = fcnList{iFcn}(vec); % Get the handle and evaluate it
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With