Explanation:
In Matlab, we can create a function that constructs a row array countValues from 0 to 25, with elements incremented by a incrementValue, this can be done in two ways;
If the value of IncrementValue is hard-coded than it will only work for IncrementValue=5, on the other hand, if the value of IncrementValue is not hard-coded than we can call CreateArray() with different IncrementValue.
1. Increment Value is hard-coded
function countValues = createArray(IncrementValue)
IncrementValue = 5;
countValues = 0:IncrementValue:25;
disp(countValues)
end
Output:
CreateArray(5)
ans = Â Â Â 0 Â Â 5 Â Â 10 Â Â 15 Â Â 20 Â Â 25
2. Increment Value is not hard-coded
function countValues = createArray(IncrementValue)
countValues = 0:IncrementValue:25;
disp(countValues)
end
Output:
CreateArray(5)
ans = Â Â Â 0 Â Â 5 Â Â 10 Â Â 15 Â Â 20 Â Â 25
CreateArray(2)
ans = Â Â Â 0 Â Â 2 Â Â 4 Â Â 6 Â Â 8 Â Â 10 Â Â 12 Â Â 14 Â Â 16 Â Â 18 Â Â 20 Â Â 22 Â Â 24
CreateArray(10)
ans = Â Â Â 0 Â Â 10 Â Â 20