Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print variable-name in Matlab

I have a function in Matlab that has some variables in it. I need to print out the variable_names (in case of an exception etc.). I am aware of inputname function but it works for input_arguments only.

mat = [ 1 2 ; 3 4 ] ;

% disp(['Error in var: ' ??(a)])
% desired ouput: Error in var: mat     (and NOT 1 2 ; 3 4!)

Thanks!

like image 1000
Maddy Avatar asked Jul 13 '11 15:07

Maddy


People also ask

How do you write variable names in MATLAB?

Valid NamesA valid variable name starts with a letter, followed by letters, digits, or underscores. MATLAB® is case sensitive, so A and a are not the same variable. The maximum length of a variable name is the value that the namelengthmax command returns.

How do you make a variable name a string in MATLAB?

varname = genvarname(str) constructs a string or character vector varname that is similar to or the same as the str input, and can be used as a valid variable name. str can be a string, a string array, a character array, a cell array of character vectors.


1 Answers

varname=@(x) inputname(1);
disp(['Error in var: ' varname(mat)])
like image 166
Grega Kešpret Avatar answered Sep 21 '22 03:09

Grega Kešpret