MATLAB Answers

create zero column vector

61 views (last 30 days)
Benjamin Cobb
Benjamin Cobb on 26 Mar 2020
Commented: Benjamin Cobb on 27 Mar 2020
I dont how to create a zero column vector in a function
I thought this was how you did it but i keep getting errors
funtion createzerocolumnvector(x)
x = zeros(56,1)
end
DOES ANYONE KNOW HOW TO DO IT?

  0 Comments

Sign in to comment.

Answers (2)

Bhaskar R
Bhaskar R on 26 Mar 2020
zeros is the MATLAB function already, its not recommended to create again a function "createzerocolumnvector(x)", use direct command as
x = zeros(10, 1); % where sencond argument should be 1 so that you get column vector, first argument says number of rows in zeros column vector
For more details read

  1 Comment

Benjamin Cobb
Benjamin Cobb on 27 Mar 2020
thanks but i need it in a funtion, all good tho found how to do it

Sign in to comment.


Peng Li
Peng Li on 26 Mar 2020
x is your input of the function, and within the function body, you overwrite it by assignment. and you don't have any output in this function. after executing, x goes out of scope.
try this if you really want a separate function to do this (although I don't understand why you are so keen on this lol):
function y = createZeroColumn(n)
y = zeros(n, 1);
end
Use y = createZerosColumn(56); to call this function, and y is the result you want.