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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
muhammad komugabe
le 17 Juin 2017
Réponse apportée : muhammad komugabe
le 6 Sep 2017
for ii=1:size(ug_waterthickness_deficits,3);
xlswrite('GRACE2_UG.xls', ug_waterthickness_deficits(:,:,ii),['month_' num2str(ii)]);
end
Réponse acceptée
Jan
le 19 Juin 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 commentaires
Image Analyst
le 19 Juin 2017
I don't see how this solved the problem. The code does NOT create a range. There are three input arguments to xlswrite.
- The first input argument is 'GRACE2_UG.xls' and it is the filename.
- The second is ug_waterthickness_deficits(:,:,ii) and it is the numerical data.
- 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
le 19 Juin 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.
Plus de réponses (2)
Image Analyst
le 17 Juin 2017
Modifié(e) : Image Analyst
le 17 Juin 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 commentaires
Jan
le 20 Juin 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.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!