# i want to find the values in the x axis for the respective y axis

4 views (last 30 days)
i have written a code for autocorrelation and got the plot for .nc file . Now i want to find the value of x axis for the respective y axis(at 0.5 and 0 )i.e.value for the first intersection of yaxis at 0.5 and 0 with the x axis.
% m - columns
% n - rows
[n,m] = size(Y);
Ym = zeros(n,m);
N = sum(Y==Y);
lag = min(N) - 1; % lag is 20
acf = zeros(lag+1,m); % auto correlation results
for i = 1:m
n = N(i);
ymean = mean(Y(1:n,i));
Ym(1:n,i) = Y(1:n,i)-ymean;
for k = 0:lag
tot = 0;
idivisor = 0;
y = Y(:,i);
for j = 1:(n-k)
tot = tot + Ym(j,i)*Ym(j+k,i);
end
for j = 1:n
idivisor = idivisor + (Ym(j,i)*Ym(j,i));
end
acf(k+1,i) = tot/idivisor;
end
end
for i = 1:m
plot(acf(:,i)),xlabel('Lag'),ylabel('SWH'),title('Autocorrelation');
grid minor;
set(gca,'xminortick','on');
set(gca,'xtick',0:50:1200);
filename = sprintf('%d',i);
print(filename,'-dpng');
end

Jakob B. Nielsen on 4 Feb 2020
You seem to do your autocorrelation in steps of 1. What is the precision you are after? Is it simply "the first time SWH drops below 0.5 or 0", respectively? Because then, a simple way is to just use the find function.
Example:
yyy=acf(:,1); %For the sake of example I just take the SWH values from your first plot.
index1=find(yyy < 0.5); %This will give a vector of all the indexes of yyy, where the value is smaller than 0.5
%In this example, index1(1) is 20, which means yyy(20) is the first value of yyy below 0.5. The corresponding x value is simply xxx(20).
%You can also just type yyy(index1(1)) and xxx(index1(1)) to get the values out.
If you need "more precision", ie. you need to know the actual intersect point and not just the step, then combine the point you find above with the point immediately before that, make a simple linear fit with those two x,y pairs, and find the values that satisfy your condition, but that takes a few lines of coding extra.