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

 Accepted Answer

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

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.
@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)

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

Dear image analyst, i am running the code but it still returns the same error yet i have cross checked and all seems ok.
for ii=1:size(ug_waterthickness_deficits,3)
xlswrite('GRACE2_UG.xls', ug_waterthickness_deficits(:,:,ii),['month_' num2str(ii)]);
end
Error using xlswrite (line 207)
Invalid data range: .
That is not the complete error message. You snipped out a small, and useless, part of it. Please post ALL the red text.
@simon, after dropping the error with simon's approach, it worked a litlle fine but later on the errors came back and now all the script cannot run fine.
@image analyst, let me paste the whole text and may be you may see it and help me to correct it. But all in all thanks for the efforts. below is the whole code execution
Warning: Function repmat has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. Warning: Function repmat has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. > In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmi\settings_mgr.p>settings_mgr at 26 In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmiml\selectionLink.p>selectionLink at 24 Warning: Function repmat has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. > In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmi\settings_mgr.p>settings_mgr at 26 In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmiml\selectionLink.p>selectionLink at 24 >> load('GRCTellus.CSR.200204_201607.LND.RL05.DSTvSCS1409_Uganda.mat'); Warning: Function repmat has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. > In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmi\settings_mgr.p>settings_mgr at 26 In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmi\initialize.p>initialize at 27 In rmi at 180 In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmi\linktype_mgr.p>linktype_mgr at 86 In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmiml\selectionLink.p>selectionLink at 27 Warning: Function repmat has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. > In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmi\settings_mgr.p>settings_mgr at 26 In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmi\initialize.p>initialize at 27 In rmi at 180 In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmi\linktype_mgr.p>linktype_mgr at 86 In C:\Program Files\MATLAB\R2013b\toolbox\slvnv\reqmgt\+rmiml\selectionLink.p>selectionLink at 27 >> climatology=NaN(size(Ug_waterthickness)); for ii=1:7; for jj=1:7 for m=1:12 ind=find(month(timenew)==m); climatology(ii,jj,ind)=nanmean(Ug_waterthickness(ii,jj,ind)); % this creates a timeseries of monthly vareages that repeats every 12 months clear ind end end end Undefined function or variable 'Ug_waterthickness'.
>> ug_waterthickness_deficits=Ug_waterthickness-climatology; Undefined function or variable 'Ug_waterthickness'.
>> for ii=1:size(ug_waterthickness_deficits,3); xlswrite('GRACE2_UG.xls', ug_waterthickness_deficits(:,:,ii),['month_' num2str(ii)]); end
@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.

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 Loops and Conditional Statements 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!