Error when attempting to use xlswrite function to print 2d array to existing Excel file
Show older comments
Hello all,
I am attempting to ease my workload by having my code print the array containing my results to an existing Excel file that is in the same filepath as my script. Here is my issue:
The line including xlswrite:
xlswrite(TestData1.xlsx, dataComp, 1, O2)
The error that is generated at an attempt to run:
Struct contents reference from a non-struct
array object.
The array that I am printing to the Excel file was created initially using the "zeros" function, and was then populated index-by-index. Because of this, I assumed that its format would be that of a numeric matrix. However, the above error makes that seem incorrect. Any advice?
Best, Jack
1 Comment
Nagarjuna Manchineni
on 26 May 2017
I believe you are trying to use xlswrite('TestData1.xlsx', dataComp, 1, O2) for writing datComp variable to O2 range in sheet 1 of TestData1.xlsx
- Can you export the 'dataComp' and 'O2' variable into a .mat file and attach to your post.
- Are you able to write the same data using 'csvwrite'?
- Are you receiving this error with any other matrix (just with zeros)?
Answers (1)
Jan
on 26 May 2017
TestData1.xlsx is treated as a struct withe the field 'xlsx'. But you mean a file name, which is a string. Then you need quotes (as Nagarjuna Manchineni has mentioned already):
xlswrite('TestData1.xlsx', dataComp, 1, 'O2')
You have written.
the above error makes that seem incorrect
Fortunately you do not have to guess, what the problem is, but you can check this by using the debugger. Type this in the ciommand window:
dbstop if error
Now run the code again, until it stops at the error. Now examine the locally used variables: Type this in the command window line by line:
TestData1.xlsx
dataComp
1
O2
Now Matlab will tell you, which variable causes the problem.
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!