Plot the tidal ellipses for the four major tidal constituents
20 views (last 30 days)
Show older comments
%% t_tide 이용하기
clc; clear all;
% 데이터 읽기
data = readtable('덕적도_실시간관측_조위.csv', 'TextType', 'string', 'Encoding', 'euc-kr', 'VariableNamingRule', 'preserve');
time = data.("관측시간"); % '관측시간' 열 이름을 정확히 입력하세요
elevation = data.("실측조위(Cm)");
% t_tide 함수를 사용하여 조석 분석 수행
[NAME, FREQ, TIDECON, ~] = t_tide(elevation, 'interval', 1/60, 'start time', datenum(time(1)), 'latitude', 35.58733);
% 주요 조석 성분 정보
major_constituents = {'M2', 'S2', 'K1', 'O1'};
colors = {'r', 'g', 'b', 'k'}; % 각각 빨강, 초록, 파랑, 검정
figure;
hold on;
for i = 1:length(major_constituents)
% 해당 조석 성분의 인덱스를 찾기
idx = find(strcmp(NAME, major_constituents{i}));
if ~isempty(idx)
% 타원 그리기 위해 필요한 매개변수 추출
major_axis = TIDECON(idx, 1); % 주축 길이
minor_axis = TIDECON(idx, 3); % 부축 길이
inclination = TIDECON(idx, 5) * pi / 180; % 도를 라디안으로 변환
x0 = 0; % 타원의 중심 x 좌표
y0 = 0; % 타원의 중심 y 좌표
% ellipsedraw 함수 호출
ellipsedraw(major_axis, minor_axis, x0, y0, inclination, colors{i});
end
end
xlabel('cm/s');
ylabel('cm/s');
title('Tidal Ellipses for Major Constituents');
legend(major_constituents);
grid on;
hold off;
.
I want to play Plot the temporal elipses for the four major temporal constructions, but nothing is coming out of the plot. Please help
0 Comments
Accepted Answer
William Rose
on 5 Nov 2024
Edited: William Rose
on 5 Nov 2024
@은진,
The line
idx = find(strcmp(NAME, major_constituents{i}));
does not work, because
strcmp(NAME, major_constituents{i})
returns a 0, even when there is a match. To fix this, I converted NAME to a cell array, and used strcmp on the cell array:
NAMEc=cellstr(NAME); % convert character array NAME to cell array
...
idx = find(strcmp(NAMEc, major_constituents{i}));
The line
inclination = TIDECON(idx, 5) * pi / 180; % 도를 라디안으로 변환
does not work, because TIDECON has only 4 columns. Column 4 is the inclination. Therefore I change the line to
inclination = TIDECON(idx, 4) * pi / 180; % 도를 라디안으로 변환
I do not have function ellipsedraw(), so I wrote my own function, drawEllipse(). I call it:
drawEllipse(major_axis, minor_axis, x0, y0, inclination, colors{i});
It works. Now the script runs. There is a warning error at line
legend(major_constituents);
because major_constituents has four strings, but the plot has only two sets of data. Therfore I modified the code to make a cell array of strings, legstr , which includes only names of the tidal components plotted. The script, with the changes described above, is attached. It runs without error. It makes the plot shown below.
Only two components are plotted, because you search for components M2, K1, S2, O1. Of these, only M2 and K1 are among the eight components returned by t_tide, for this data set.
2 Comments
More Answers (0)
See Also
Categories
Find more on Surfaces, Volumes, and Polygons 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!