function doesnt works well
显示 更早的评论
Hi, I am using this function;
function [s,tint] = spei(t,prec,pevap,varargin)
But, I am not sure what is varargin works for?
The size of my file are;
t=1x1x420
prec=98x56x420
pevap=98x56x420
Error using spei (line 40)
Expected a string scalar or character vector for the parameter name.
2 个评论
Star Strider
2021-12-20
It will be necessary to carefully read the documentation for the file to understand what the arguments must be, and what their order must be.
Rik
2021-12-20
Function posted in duplicate question:
function [spei_index]=calculate_spei(t,prec,pevap,varargin);
[nlon, nlat, n]=size(prec);
prec=squeeze(prec);
for i=1:nlon
for j=1:nlat
if isnan(prec(i,j,1))==0
spei_index(i,j,:)=spei(t,prec(i,j,:),pevap(i,j,:),varargin);
else
spei_index(i,j,:)=ones(1,n-12)*NaN;
end
end
end
回答(2 个)
Walter Roberson
2021-12-20
spei_index(i,j,:) = spei(t, prec(i,j,:), pevap(i,j,:), varargin{:} );
is my guess.
5 个评论
Rik
2021-12-21
Good catch, I should have spotted this. I'll leave my answer up for documentary purposes.
Nurul Ain Basirah Zakaria
2021-12-21
Walter Roberson
2021-12-21
No, that is not needed. The documentation states
% s = spei(t,prec,pevap) computes the standardised precipitation-evapotranspiration
% index s, given precipitation prec and potential evaporation pevap corresponding
% to times t. prec and pevap can be either be 1D vectors or 3D cubes, whose
% first two dimensions are spatial and whose third dimension corresponds to times
% t. The dimensions of prec and pevap must agree. Times t can be datetime
% or datenum format.
so passing in a vector of times of length 420 is fine if your prec and pevap are something by something by 420.
Nurul Ain Basirah Zakaria
2021-12-21
Nurul Ain Basirah Zakaria
2021-12-21
varargin is typically used to capture optional input arguments:
help varargin
Since you don't use the optional/unnamed inputs, there shouldn't be any issues.
The function you're using should have documentation explaining how to use it. Read it. If you don't understand it, please provide a reference to where you got this function (as I can't find it).
2 个评论
Nurul Ain Basirah Zakaria
2021-12-21
Walter Roberson
2021-12-21
In that case my suggestion was correct.
类别
在 帮助中心 和 File Exchange 中查找有关 Detection 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!