- Try reducing the fet value. A smaller fet means the function will try to fit the data more closely.
- Increase the dod value. A higher dod means the function will use more observations to fit the harmonic function, which might result in a better fit.
How do I define HANTS matlab parameters?
7 views (last 30 days)
Show older comments
I am using HANTS MATLAB code for the NDVI time series. I have defined the parameters as follows;
function [yOut, amp, phi]=ApplyHants(y,nb,nf,fet,dod,HiLo,low,high,delta)
nb = 22 ; total number of images
nf = 3 frequency above zero frequency
fet = 5
dod = 5
HiLo = 'none'
low = -1.0 ; minimum value of NDVI
high = 1.0 ; maximum value of NDVI
delta = 0.1
but it is giving output as zero values.
Please suggest me how to define these above mentioned parameters for my NDVI time series of one year time period having 22 images.
I would appreciate your kind help.
Gauri
5 Comments
Answers (2)
Manikanta Aditya
on 3 May 2024
Edited: Manikanta Aditya
on 3 May 2024
Hi @gauri
Please consider these as my suggestations from my research and exploration and try to see if you can resolve the issue. Might not completely fix the issue.
From your description, it seems like the dimensions of your input data might not be matching the expected dimensions in the 'ApplyHants' function. The function expects the input data to be three-dimensional in the form [time, lat, lon], but your data seems to be in the form [bands, lines, samples].
You can try transposing your data to match the expected dimensions.
Here’s how you can do it:
% Transpose the dimensions
image = permute(image, [3 2 1]);
% Now pass the transposed image to the function
[yOut, amp, phi] = ApplyHants(image, nb, nf, fet, dod, HiLo, low, high, delta);
This will rearrange your data dimensions to match the expected [time, lat, lon] format. Please try this and let me know if it helps.
By using permute(image, [1, 3, 2]), you are rearranging the dimensions of the image array to [time, samples, lines], which should match the expected order [time, lat, lon] for the ApplyHants function.
After making this change, the ApplyHants function should work as expected, and you should get the desired output instead of zero values.
8 Comments
Manikanta Aditya
on 5 May 2024
Edited: Manikanta Aditya
on 5 May 2024
The error you're encountering is related to the way MATLAB handles logical operations with arrays. In MATLAB, the && and || operators expect scalar inputs or arrays of the same size. However, the condition any(~ready) returns a single logical value (true or false), which is incompatible with the array ready in the expression any(~ready) && (nloop < nloopmax).
To fix this issue, you can replace the logical AND operation (&&) with the element-wise AND operation (&), and wrap the condition with the any function, like this:
while any(~ready & (nloop < nloopmax))
% ... rest of the loop code ...
end
This way, the element-wise AND operation (&) is performed between the negated ready array (~ready) and the condition nloop < nloopmax, and then the any function checks if any element in the resulting logical array is true.
Alternatively, you can restructure the condition using && and any separately, like this:
while (any(~ready)) && (nloop < nloopmax)
% ... rest of the loop code ...
end
In this case, the any(~ready) expression returns a single logical value, which can be used with the && operator along with the scalar condition nloop < nloopmax.
John
on 10 May 2024
The error "Arrays have incompatible sizes for this operation" is likely due to a mismatch in the dimensions of the arrays involved in the element-wise multiplication operation
mat .* (p .* y)
In the HANTS code, the line
mat = zeros(min(2*nf+1, ni), ni);
initializes a matrix mat with dimensions
(min(2*nf+1, ni), ni)
. However, the dimensions of the arrays p and y are not explicitly specified in the code snippet you provided. To resolve this issue, you need to ensure that the dimensions of mat , p , and y are compatible for element-wise operations.
Here are a few steps you can try: Check the dimensions of your input data y by using the size function:
[ni, ny, nx] = size(y);
Ensure that the dimensions of mat match the expected dimensions based on the input data y .
The first dimension of mat should be
min(2*nf+1, ni)
, and the second and third dimensions should match the dimensions of y . You can modify the initialization of mat as follows:
mat = zeros(min(2*nf+1, ni), ny, nx);
Initialize the array p with the same dimensions as y :
p = ones(ni, ny, nx);
Modify the line that creates the logical array bool_out to ensure that the dimensions match:
bool_out = (y < low) | (y > high);
Update the line that assigns values to p based on bool_out :
p(bool_out) = 0;
Update the line that calculates nout :
nout = sum(p == 0, 'all');
After making these changes, the dimensions of mat , p , and y should be compatible, and the element-wise multiplication operation
mat .* (p .* y)
should work correctly. If you still encounter issues, provide more information about the dimensions of your input data y and the specific error message you receive.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!