table on workspace isn't recognized as table
이전 댓글 표시
Hi,
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(:,4),left_precentral(:,5),left_precentral(:,6),...
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:
writetable(left_precentral_betas,[PATHOUT,'left_motor.txt']);
I get this error:
Error using writetable (line 139)
First argument must be a table.
istable(left_precentral_betas);
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,
Hatice
댓글 수: 6
Walter Roberson
2020년 2월 4일
What shows up for
class(left_precentral_betas)
Hatice Sahin
2020년 2월 4일
Guillaume
2020년 2월 4일
Note that this won't solve your problem at all but a much simpler way to construct your table would be with:
%if size(left_precental, 2) is 6:
left_precentral_betas = array2table(left_precentral, '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'});
%if not
left_precentral_betas = array2table(left_precentral(:, 1:6), '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'});
Now, with regards to your problem, can you issue at the command prompt
dbstop if error
then attempt to write the table. When it errors, it will stop in the debugger inside writetable. At this point, what is
class(T)
Also, what is
which istable -all
Hatice Sahin
2020년 2월 4일
Walter Roberson
2020년 2월 4일
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
2020년 2월 5일
채택된 답변
추가 답변 (2개)
Subhadeep Koley
2020년 2월 4일
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.
clc;
% 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']);
댓글 수: 4
Hatice Sahin
2020년 2월 4일
Walter Roberson
2020년 2월 4일
편집: Walter Roberson
2020년 2월 4일
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
2020년 2월 5일
Walter Roberson
2020년 2월 5일
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')
Or
T{:, 'Right Palm Media'}
But it is supported for R2019b onwards.
Daniel M
2020년 4월 24일
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'))
restoredefaultpath
startup;
ft_dir = path/to/main/fieldtrip/folder;
run(fullfile(ft_dir,'ft_defaults.m'));
end
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:
카테고리
도움말 센터 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!