Error using writetable: expect input to be one of these types

Dear all,
I'm trying to write a simple table with writetable, but I get an error message for which I did not find an explanation even after quite some investigations. The problem is as follows:
>> writetable(table((1:10)'))
leads to the following error message:
"Error using writetable (line 121) Expected input to be one of these types:
char
Instead its type was cell."
>> which writetable
shows: "/Applications/MATLAB_R2016b.app/toolbox/matlab/iofun/writetable.m"
and
>> which write
shows: "write is a built-in method % asyncioimpl.OutputStream method"
I'm sceptical whether the last output is really what I should get.
>> open write
opens a write function which does "Write data to a figure file."
Does anyone have any ideas on what's wrong here?
I'm using MATLAB 9.1.0.441655 (R2016b)
Best,
Christoph

 Accepted Answer

Thanks a lot!
The output of
>> which -all write
is
write is a built-in method % asyncioimpl.OutputStream method
/Applications/MATLAB_R2016b.app/toolbox/shared/asynciolib/+asyncio/OutputStream.m % asyncio.OutputStream method
write is a Java method % org.apache.commons.io.output.NullOutputStream method
write is a Java method % java.io.OutputStream method
write is a Java method % java.io.PrintStream method
write is a Java method % java.io.FilterOutputStream method
/Applications/MATLAB_R2016b.app/toolbox/matlab/datatypes/@table/write.m % table method
/Applications/MATLAB_R2016b.app/toolbox/matlab/bigdata/@tall/write.m % tall method
/Applications/MATLAB_R2016b.app/toolbox/bioinfo/bioinfo/@BioRead/write.m % BioRead method
/Applications/MATLAB_R2016b.app/toolbox/bioinfo/bioinfo/@BioMap/write.m % BioMap method
/Applications/MATLAB_R2016b.app/toolbox/idelink/extensions/ticcs/@ccsdebug/write.m % ccsdebug method
/Applications/MATLAB_R2016b.app/toolbox/wavelet/wavelet/@wptree/write.m % wptree method
/Applications/MATLAB_R2016b.app/toolbox/wavelet/wavelet/@wdectree/write.m % wdectree method
/Applications/MATLAB_R2016b.app/toolbox/wavelet/wavelet/@dtree/write.m % dtree method
How can I call a specific "write", particularly "...@table/write"?
Btw, the first line of code I posted IS a small example, isn't it? This line here:
>> writetable(table((1:10)'))

4 Comments

This should have been a comment to the previous answer, sorry!
Sorry, I read too quickly and did not notice that you'd already created a short example.
I can't reproduce that in R2016b. I guess you are looking at write because you went to line 121 in writetable. It looks like you have the correct write method, perhaps you could set a breakpoint in writetable and step into the write method and see what's going on where the error actually happens.
Thanks for the quick response!
I was able to trace the problem down. In contrast to what is suggested by the error message, the error was not caused by line 121 of writetable, but actually by a use of strjoin. Stepping inside 'write', and running line 154 delivers this error:
>> writeTextFile(t,filename,otherArgs)
Error using strjoin (line 14)
Expected input to be one of these types:
char
Instead its type was cell.
Error in tabular/writeTextFile>writeHeader (line 336)
headerFmt = [strjoin(repmat({'%s'},1,length(varHeaders)), writeParams.delimiter), '\n'];
Error in tabular/writeTextFile (line 52)
writeHeader(fid, adata, avarnames, writeParams, varTraits);
In my setup Matlab's strjoin appears to be shadowed by a custom strjoin function from some plugin. So, solved now. Thanks!
The error comes from line 121 in writetable, because write has a try/catch/throwAsCaller in it. One way to get to the actual line where the error occurred is
dbstop if caught error
but you'll want to be sure to dbclear at some point else you'll be stopping in the debugger all over the place. Glad you found the problem.

Sign in to comment.

More Answers (1)

which -all write
But I think you're going to have to post a SMALL example of a table for which you see this error.

Categories

Products

Community Treasure Hunt

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

Start Hunting!