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
採用された回答
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 件のコメント
Salim
2024 年 4 月 28 日
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?
Salim
2024 年 4 月 28 日
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
Salim
2024 年 4 月 29 日
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.
Salim
2024 年 5 月 1 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
