data extraction for a specific period over a long data.

Hi Folks,
I have written the following script and it works for a single period correctly. Can some one help me to amend the code to look at the every 500 steps and compare 50 steps over the file of 1000 steps after comparing the 2 files.
NN=1000;
N=50;
for i=1:NN
for j=1:N
if (east(j)== xx(i))
if (north(j)==yy(i))
x(j)=xx(i);
y(j)=yy(i);
ele(j)=zz(i);
UU(j)=u(i);
VV(j)=v(i);
hh(j)=h(i);
end
end
end
end

 Réponse acceptée

Hi @Salim,
Check this code where I modified the script to compare every 500 steps and 50 steps over a file of 1000 steps:
To modify the code to look at every 500 steps and compare 50 steps over a file of 1000 steps, you can use nested loops with appropriate step sizes.
NN = 1000; % Total number of steps
N = 50; % Number of steps to compare
step_size = 500; % Step size for comparison
for i = 1:step_size:NN % Loop over every 500 steps
for j = 1:N % Loop over the 50 steps to compare
if (east(j) == xx(i+j-1)) % Check if east coordinate matches
if (north(j) == yy(i+j-1)) % Check if north coordinate matches
x(j) = xx(i+j-1); % Store x coordinate
y(j) = yy(i+j-1); % Store y coordinate
ele(j) = zz(i+j-1); % Store elevation
UU(j) = u(i+j-1); % Store u value
VV(j) = v(i+j-1); % Store v value
hh(j) = h(i+j-1); % Store h value
end
end
end
end
Hope this helps.

7 commentaires

Thank you very much for your effort. The script did not work. I think we need to put a counter for 500 steps in which my script will compare the 50 steps with first 500 steps. Then it goes to compare again the same 50 steps with the second 500 steps. So, Please can we add this counter?
Hi Dear,
In the following script I modified the script with a counter, but still compares the 50 steps over the first 500 steps from the file that has a 10000 steps. Now, what I need is to make the script to go over the other 500 steps.
kk=0; tt=1;
for i=1:NN
kk=kk+i;
if (kk <= tt*500) %This will read the first 500
for j=1:N
if (east(j)== xx(i))
if (north(j)==yy(i))
easting(j)=xx(i);
northing(j)=yy(i);
ele(j)=zz(i);
UU(j)=u(i);
VV(j)=v(i);
hh(j)=h(i);
end
end
end
tt=tt+1;
end
end
To achieve the functionality you're asking for, where the script compares the same 50 steps with each 500-step segment of your 1000-step data, you can implement a counter and adjust the loop structure accordingly.
NN = 1000; % Total number of steps
N = 50; % Number of steps to compare
step_size = 500; % Step size for comparison
% Assuming xx, yy, zz, u, v, h are defined somewhere in your code
% Initialize the arrays x, y, ele, UU, VV, hh to store matched data
x = zeros(N,1);
y = zeros(N,1);
ele = zeros(N,1);
UU = zeros(N,1);
VV = zeros(N,1);
hh = zeros(N,1);
for segment_start = 1:step_size:NN % Loop over segments of 500 steps
for j = 1:N % Loop over the 50 steps to compare
for i = segment_start:min(segment_start+step_size-1, NN) % Loop over each step in the current 500-step segment
if (east(j) == xx(i)) && (north(j) == yy(i)) % Check if coordinates match
% Store matched data
x(j) = xx(i);
y(j) = yy(i);
ele(j) = zz(i);
UU(j) = u(i);
VV(j) = v(i);
hh(j) = h(i);
break; % Stop searching once a match is found for this j
end
end
end
end
Sirm it does not work again. It gives 0 results for the second 500 steps and I think if we can amend this line
for i = segment_start:min(segment_start+step_size-1, NN) % Loop over each step in the current 500-step segment
Thanks in advance
Hi @Salim,
Based on the description and the issues you've encountered, it seems like the main problem is ensuring that the script correctly compares each set of 50 steps with both the first and second 500-step segments of your 1000-step data. The goal is to ensure that the comparison is made correctly across both segments without missing any data.
Here's a revised version of the script that should address the issue:
NN = 1000; % Total number of steps
N = 50; % Number of steps to compare
step_size = 500; % Step size for comparison
% Assuming xx, yy, zz, u, v, h are defined somewhere in your code
% Initialize the arrays to store matched data for each segment
% Since we have two segments (1-500 and 501-1000), we need to store data for both
x = zeros(N,2);
y = zeros(N,2);
ele = zeros(N,2);
UU = zeros(N,2);
VV = zeros(N,2);
hh = zeros(N,2);
% Counter for tracking which segment (1st or 2nd) we're matching against
segment_counter = 1;
for segment_start = 1:step_size:NN % Loop over segments of 500 steps
for j = 1:N % Loop over the 50 steps to compare
for i = segment_start:min(segment_start+step_size-1, NN) % Loop over each step in the current 500-step segment
if (east(j) == xx(i)) && (north(j) == yy(i)) % Check if coordinates match
% Store matched data in the column corresponding to the current segment
x(j,segment_counter) = xx(i);
y(j,segment_counter) = yy(i);
ele(j,segment_counter) = zz(i);
UU(j,segment_counter) = u(i);
VV(j,segment_counter) = v(i);
hh(j,segment_counter) = h(i);
break; % Stop searching once a match is found for this j
end
end
end
% Move to the next segment after finishing the comparisons for the current one
segment_counter = segment_counter + 1;
end
% Note: The result matrices (x, y, ele, UU, VV, hh) have 2 columns, one for each 500-step segment.
This new script should correctly compare the specified 50 steps against both 500-step segments of your data and store the results in a way that allows you to see which matches were found in each segment. If you face any errors, do try resolving them please, if this helps feel free to accept the answer @Salim!
Thanks.
Thank you very much. It is now working. Many thanks for your support and dedication.
Great to hear @Salim!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by