MATLAB Answers

How do I define a variable without assigning it a value?

3,638 views (last 30 days)
Ethan Sehrt
Ethan Sehrt on 16 Jun 2016
Commented: Walter Roberson on 22 Jan 2020
I just want to define a variable, f without assigning any values to it so I can use it in an equation.

  1 Comment

James Tursa
James Tursa on 16 Jun 2016
Do you mean symbolically? E.g.,
syms f
Or maybe you mean an anonymous function? E.g.
myfunction = @(f)f+3

Sign in to comment.

Answers (4)

Star Strider
Star Strider on 16 Jun 2016
You can also assign a variable as an empty matrix, cell, string (or any other empty value):
x = []; % Empty Scalar, Vector Or Matrix
y = {}; % Empty Cell
z = ''; % Empty String Or Character


Walter Roberson
Walter Roberson on 22 Jan 2020
w = zeros(0,0, 'uint8'); %empty variable but uint8 datatype
w = uint8([]); %empty variable but uint8 data type

Sign in to comment.

Walter Roberson
Walter Roberson on 22 Jan 2020
You can use James' File Exchange contribution to create an uninitialized array. The initial contents of the variable will be whatever happened to be in memory,


Sign in to comment.

Community Treasure Hunt

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

Start Hunting!