Hello, i have the following code but whenever i run it, it returns an error that " Error using xlswrite (line 207) Invalid data range: ."

1 view (last 30 days)
for ii=1:size(ug_waterthickness_deficits,3);
xlswrite('GRACE2_UG.xls', ug_waterthickness_deficits(:,:,ii),['month_' num2str(ii)]);
end

Accepted Answer

Jan
Jan on 19 Jun 2017
If the line
xlswrite('GRACE2_UG.xls', ug_waterthickness_deficits(:,:,ii),['month_' num2str(ii)]);
produces the error
Error using xlswrite (line 207)
Invalid data range: .
the code creates a range, which includes a ".". Use the debugger to find out, where this dot is coming from: Type this in the command window:
dbstop if error
Then run the code again until it stops at the error. Now check what has been provided as range. You have to search in the caller workspaces and if you are not familiar with using the debugger, this is the best time to learn how to use it:
docsearch debugger
Alternatively, you can display the values directly in the code:
disp(ug_waterthickness_deficits(:,:,ii))
disp(['month_' num2str(ii)])
xlswrite('GRACE2_UG.xls', ug_waterthickness_deficits(:,:,ii),['month_' num2str(ii)]);
I do not see, where the dot is coming from, but you have all information to solve this problem on your computer.
  2 Comments
Image Analyst
Image Analyst on 19 Jun 2017
I don't see how this solved the problem. The code does NOT create a range. There are three input arguments to xlswrite.
  1. The first input argument is 'GRACE2_UG.xls' and it is the filename.
  2. The second is ug_waterthickness_deficits(:,:,ii) and it is the numerical data.
  3. The third is ['month_' num2str(ii)] and it is a string that is interpreted as a sheet name.
There is no fourth input argument, and so no range is specified.
Like I said, if he's getting that error, he didn't give us the correct code. In fact I ran the exact code he gave and it ran fine. Plus he's not giving us the complete error message - ALL the red text - like I asked so we don't really know the line of code that is throwing the error.
Jan
Jan on 19 Jun 2017
@Image Analyst: You are right, this message does not solve the problem directly. But perhaps using the debugger let the OP find the line, which is really failing.

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 17 Jun 2017
Edited: Image Analyst on 17 Jun 2017
It works fine. I just tried it:
ug_waterthickness_deficits = rand(4,5,6);
for ii=1:size(ug_waterthickness_deficits,3)
xlswrite('GRACE2_UG.xls', ug_waterthickness_deficits(:,:,ii),['month_' num2str(ii)]);
end
In your code, you may have left out a comma or added an extra one. For some reason it thinks ['month_' num2str(ii)] is not the sheet name, but thinks it's the cell reference instead. Please post your ACTUAL code along with ALL the red text.
  5 Comments
Jan
Jan on 20 Jun 2017
@muhammad komugabe: It seems like you have created a file called "repmat.m", but this collides with Matlab's built-in function.
The message "Undefined function or variable 'Ug_waterthickness'" is clear also. Perhaps you want a lower-case 'u'?
Please take the time to read the error messages by your own.

Sign in to comment.


muhammad komugabe
muhammad komugabe on 6 Sep 2017
Hey team, I want to calculate a time series average for the assigned regions (Northern , Eastern , southern and central as shown in the map) for this map, using a 6x6 cell data as shown in the excel sheet(ignore the first column and last row to suit the shape read). Kindly help me. thanks
Please refer to excel sheet for clarity. I will be glad for any useful help. Thanks

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!