MATLAB Answers

0

How to convert xlswrite to writematrix?

Asked by Jojo Blanza on 7 May 2019
Latest activity Commented on by Jeremy Hughes on 8 May 2019
I have a code that uses xlswrite and works in R2016. When I run it in R2019a Matlab online, it gives an error on xlswrite and suggests to use writematrix instead. I followed the format of writematrix, however, there is still an error using writematrix. How do I convert xlswrite to writematrix? Thanks.

  3 Comments

dpb
on 7 May 2019
Not enough details...what's the xlswrite error, specifically, first, and attach the data as .mat file...or at least tell us what the content is.
If xlswrite really fails in R2019a and succeeds with the identical data on the same system with earlier release, I'd say that would qualify as a bug...just having introduced some new feature should not break earlier.
However, writematrix can only deal with homogeneous data altho one would hope the error message would suggest writecell instead if that were the issue...
All in all, just not enough info for even the crystal ball...
If you say you get an error always give us the full text of the error message (everything that is red).
Note that matlab online runs on linux, so writematrix and more so xlswrite are limited in what they can write to an excel file.
dpb
on 7 May 2019
Ah...I was unaware of that tho makes sense...that in fact is likely the root cause indeed for xlswrite; still indeterminate for writematrix

Sign in to comment.

Products


Release

R2019a

2 Answers

Answer by Jeremy Hughes on 7 May 2019

XLSWRITE can write either a matrix (e.g. [ 1 2 4;5 7 8] or a cell {'a' 'b';'c' 'd'})
If your input is a cell, use WRITECELL.

  2 Comments

The input to the matrix are numbers (values). Does it mean that I should use writematrix? Also, Matlab Online suggests writematrix instead of xlswrite.
Thanks.
Based on the comment below:
writematrix(dataset,filename,sheet,xlRange)
should be:
writematrix(dataset,filename,'Sheet',sheet,'Range',xlRange)

Sign in to comment.


Answer by Jojo Blanza on 8 May 2019

Appreciate your responses.
Here are the errors:
Error using writematrix (line 134)
Invalid parameter name: Indo_Sing_Wide_LOS-1
Error in A_DataGeneration (line 207)
writematrix(dataset,filename,sheet,xlRange)
Apologies for forgeting to include the errors.
Thanks for your answers.

  1 Comment

dpb
on 8 May 2019
What if you use writematrix but to a text file? I'm betting odds are good that will work and if so it's related to the issue of is Excel actually supported for the platform you're trying to write to as Guillaume suggested.
But, it would still be agoodthing™ if we could see the actual form of the data you're trying to write; I wonder with the variable name dataset are you, by any chance, using a ML table or the old Statistics TB dataset class, are you??? But, if the latter, that variable name is aliasing the constructor for the class...
What does
whos dataset
return at command line?

Sign in to comment.