MATLAB Answers

table on workspace isn't recognized as table

17 views (last 30 days)
Hatice Sahin
Hatice Sahin on 4 Feb 2020
Answered: Daniel M on 24 Apr 2020
I have a question that puzzles me.
On my workspace I have a table as such:
name value
left_precentral_betas 25x8 table
and this is how I created it:
left_precentral_betas = table(left_precentral(:,1),left_precentral(:,2),left_precentral(:,3)...
left_precentral(:,7),left_precentral(:,8), 'VariableNames',...
{'Right Palm Medial', 'Right Back Medial','Left Palm Medial',...
'Left Back Medial','Right Palm Lateral','Right Back Lateral'...
,'Left Palm Lateral','Left Back Lateral'}) ;
yet I can't use writetable function:
I get this error:
Error using writetable (line 139)
First argument must be a table.
gives me 0. If it's not a table, why it's defined as table in my workspace?
If I'm defining the table wrongly, why do I have it as table in my workspace?
and how can I write or save this table/non table as .txt?
Kind regards,


Show 3 older comments
Hatice Sahin
Hatice Sahin on 4 Feb 2020
Thank you very much for your tips!
Soo, I assume I should have written class(data) instead of class(T) because I had only data, msg and writeFunctionName left on my workspace. So I did;
K>> class(data)
ans =
K>> which istable -all
C:\Program Files\MATLAB\R2019b\toolbox\matlab\datatypes\istable.m % Shadowed
Looks like the toolbox I used to analyze my data (spm12) somehow interferes with this function. How can I get rid of it?
Kind regards,
Walter Roberson
Walter Roberson on 4 Feb 2020
You should remove spm12\external\fieldtrip\compat\matlablt2013b from your path . It is intended as compatibility functions for use with versions before R2013b.
Hatice Sahin
Hatice Sahin on 5 Feb 2020
I removed it from the path and it works perfect now. Thank you very much!

Sign in to comment.

Accepted Answer

Guillaume on 4 Feb 2020
"Soo, I assume I should have written class(data)"
No, if you'd followed my instruction, when the error occured matlab should have entered the debugger in the workspace of writable (because of the dbstop if error you issued earlier). Within the workspace of writetable, your original variables don't exist and the table is called T. At least, in R2019b and I assume in previous versions as well.
Anyway, as the which shows, the problem is that the fieldtrip toolbox overrides the built-in istable with its own incompatible version.
From other questions I've seen here, the fieldtrip toolbox has a nasty habit of overriding matlab built-in functions with its own incompatible version. isrow was a particular nasty one I've seen as it prevented proper matlab startup.

  1 Comment

Hatice Sahin
Hatice Sahin on 5 Feb 2020
It works now! Thank you very much for your help.

Sign in to comment.

More Answers (2)

Subhadeep Koley
Subhadeep Koley on 4 Feb 2020
As far as my knowledge goes MATLAB does not support Blank Space in variable names. It can only contain letters, numbers or underscore. Blank spaces or symbols are not allowed. Therefore it should throw error when you are passing 'Right Palm Medial' as a variable name.
Give the below code a try. I'm not getting any error in my end with the code below.
% 20-by-20 Random data
left_precentral = rand(20, 20);
% Make the table
left_precentral_betas = table(left_precentral(:, 1), left_precentral(:, 2), left_precentral(:, 3),...
left_precentral(:, 4), left_precentral(:, 5), left_precentral(:, 6),...
left_precentral(:, 7), left_precentral(:, 8), 'VariableNames',...
{'RightPalmMedial', 'RightBackMedial', 'LeftPalmMedial',...
'LeftBackMedial', 'RightPalmLateral', 'RightBackLateral',...
'LeftPalmLateral', 'LeftBackLateral'});
% Write the table
writetable(left_precentral_betas, [PATHOUT, 'left_motor.txt']);


Show 1 older comment
Walter Roberson
Walter Roberson on 4 Feb 2020
R2019b and later do support arbitrary character vectors for variable names. (It appears that the limit is still 63 characters per name though.)
Subhadeep Koley
Subhadeep Koley on 5 Feb 2020
@ Walter Roberson I did not knew about this change. Thanks for letting me know :)
Walter Roberson
Walter Roberson on 5 Feb 2020
In order to use non-identifiers, you need to use dynamic field name syntax, or else pass the variable name as the second index
T.('Right Palm Media')
T{:, 'Right Palm Media'}
But it is supported for R2019b onwards.

Sign in to comment.

Daniel M
Daniel M on 24 Apr 2020
The issue is that you likely added the entire Fieldtrip toolbox to your path, which is not recommended. I am currently using Fieldtrip for some analysis, and it does not override the istable function in its default behaviour.
Fieldtrip does not recommend adding the whole toolbox to your path. Just run the function ft_defaults.m and it will do it properly for you.
Try it by doing:
if isempty(which('ft_preprocessing'))
ft_dir = path/to/main/fieldtrip/folder;
The purpose of the if statement is so that you don't need to alter your path everytime you run your script, since this is a time-expensive process.
See also:


Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by