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 Ansichten (letzte 30 Tage)
for ii=1:size(ug_waterthickness_deficits,3);
xlswrite('GRACE2_UG.xls', ug_waterthickness_deficits(:,:,ii),['month_' num2str(ii)]);
end

Akzeptierte Antwort

Jan
Jan am 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 Kommentare
Image Analyst
Image Analyst am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Image Analyst
Image Analyst am 17 Jun. 2017
Bearbeitet: Image Analyst am 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 Kommentare
Jan
Jan am 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.

Melden Sie sich an, um zu kommentieren.


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

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by