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

2 次查看(过去 30 天)
for ii=1:size(ug_waterthickness_deficits,3);
xlswrite('GRACE2_UG.xls', ug_waterthickness_deficits(:,:,ii),['month_' num2str(ii)]);
end

采纳的回答

Jan
Jan 2017-6-19
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 个评论
Image Analyst
Image Analyst 2017-6-19
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 2017-6-19
@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.

请先登录,再进行评论。

更多回答(2 个)

Image Analyst
Image Analyst 2017-6-17
编辑:Image Analyst 2017-6-17
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 个评论
Jan
Jan 2017-6-20
@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.

请先登录,再进行评论。


muhammad komugabe
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

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by