Creating a new plot every time there is a gap in data

조회 수: 2 (최근 30일)
Pouya
Pouya 2022년 4월 19일
답변: Pratyush Swain 2023년 10월 3일
Hi,
I have two sets of data for a day worth of a staellite measurment. y is the measurment that the satellite does and x is lattitude that the satellite is in. Since there are more than one orbit per day the lattitude value recycles every orbit. I want to make a simple plot (or a series of plots) that starts displaying (x,y) from the beginning but when there is gap in data (represnting the recycled orbit) worth of lets say 5 [degrees], it starts a new plot and so on.
Thanks,
Pouya.
  댓글 수: 2
Image Analyst
Image Analyst 2022년 4월 19일
편집: Image Analyst 2022년 4월 19일
OK. Good luck with it. If you have any questions, just ask. But if you do ask, read this link first:
and attach your data file and code to read it into a variable in MATLAB. In the meantime, use diff(x) > 5 to try to find gaps of more than 5 in x.
Pouya
Pouya 2022년 4월 19일
My appologies I rushed posting this question I should've clarified my question better.
Basically let's say we have variable x = 1 2 3 4 5 6 ... 360 1 2 3 4 5 6 ... 360 1 2... and y= y1 y2 y3 ...yn
Plotting x vs y using plot(x,y) will show all y values vs x.
My question is, how can I plot these data so that when there is a gap between the values of data x larger than 1, for example, it saves the previous plot and start a new one where x(i=366) vs y(i=366) is the first data point of the new plot?

댓글을 달려면 로그인하십시오.

답변 (1개)

Pratyush Swain
Pratyush Swain 2023년 10월 3일
Hi Pouya,
I understand you want a new plot figure everytime the latitude values are recycled.
Please refer to an example implementation below:
lat = 1:360;
x=[lat,lat,lat]; % Example x data - series of cycling repeating values
y = 100*rand(1,360*3); % Example y data
figure; % Create a new figure
startIndex = 1; % Start index of each plot segment
for i = 2:length(x)
if abs(x(i) - x(i-1)) > 1 % Check if there is a gap larger than 1
plot(x(startIndex:i-1), y(startIndex:i-1)); % Plot the segment
xlabel('latitude'); % Set x-axis label
ylabel('y'); % Set y-axis label
figure; %Create new figure after each plot
startIndex = i; % Update the start index for the next segment
end
end
plot(x(startIndex:end), y(startIndex:end)); % Plot the last segment
xlabel('latitude'); % Set x-axis label
ylabel('y'); % Set y-axis label
Three independent plots are obtained as a result of above implementation.
Hope this helps.

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by