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
채택된 답변
Manikanta Aditya
2024년 4월 28일
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
Hi @ Manikanta Aditya
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
Manikanta Aditya
2024년 4월 30일
편집: Manikanta Aditya
2024년 4월 30일
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.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Just for fun에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
