How to merge and smooth multiple curves in a plot, if there are discrete points?

조회 수: 4 (최근 30일)
I have a graph, containing 4 different types of curves, in 5 frequency regions, overall 20 curves in a single graph. At some points, the curves meet, however at some points, the curves are super distant from the following one. I applied brushing, but still have discontinuities.
(Keeping the color coding) I need to merge them and smooth the sharp and points. How can I do this?
I uploaded the fig file. I have the excel data if needed.
Best
( 1. I failed to utilize link in figure properties 2. I tried to gather the data in excel, and delete the meeting points, it also didnt work)
  댓글 수: 6
Image Analyst
Image Analyst 2024년 6월 30일
@Paul thanks for letting us know that - I didn't know. However it's still extra work - we need to write and run code - when it would be easier on us if the original poster just made it displayed right from the start.
@Zeynep Ertekin Not sure what you don't understand or what poster you were referring to. Did you not understand how to attach your data file and m-file with the paperclip icon when I requested that you do that? Or was it something else you didn't understand? Regardless, we're still waiting for your data so we can show you how to do it. It might be as simple as locating NaNs and removing them, like I already said.
badIndexes = isnan(x) | isnan(y);
x(badIndexes) = []; % Remove the bad x values.
y(badIndexes) = []; % Remove the bad y values.
Zeynep Ertekin
Zeynep Ertekin 2024년 7월 1일
Dear Image Analyst,
I add here my workspace. I appreciate your help.

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

채택된 답변

Mathieu NOE
Mathieu NOE 2024년 7월 2일
hello
tried afew options, probably here my best result in the very limited time I have now :
this is a demo on the first two line plots , extend to the other plots if you like it
load('dataread_matlab.mat')
% figure
% plot(TEM_34_S{:,3},-1*TEM_34_S{:,4},'r',TEM_62_S{:,3},-1*TEM_62_S{:,4},'r',TEM_90_S{:,3},-1*TEM_90_S{:,4},'r',TEM_159_S{:,3},-1*TEM_159_S{:,4},'r',TEM_284_S{:,3},-1*TEM_284_S{:,4},'r','LineWidth',4);
% hold on
% plot(TEM_34_S{:,7},-1*TEM_34_S{:,8},'b',TEM_62_S{:,7},-1*TEM_62_S{:,8},'b',TEM_90_S{:,7},-1*TEM_90_S{:,8},'b',TEM_159_S{:,7},-1*TEM_159_S{:,8},'b',TEM_284_S{:,7},-1*TEM_284_S{:,8},'b','LineWidth',4);
% hold on
%%
channel = 4;
x1 = [TEM_34_S{:,channel-1};TEM_62_S{:,channel-1};TEM_90_S{:,channel-1};TEM_159_S{:,channel-1};TEM_284_S{:,channel-1}];
y1 = [TEM_34_S{:,channel};TEM_62_S{:,channel};TEM_90_S{:,channel};TEM_159_S{:,channel};TEM_284_S{:,channel}];
%%
channel = 8;
x2 = [TEM_34_S{:,channel-1};TEM_62_S{:,channel-1};TEM_90_S{:,channel-1};TEM_159_S{:,channel-1};TEM_284_S{:,channel-1}];
y2 = [TEM_34_S{:,channel};TEM_62_S{:,channel};TEM_90_S{:,channel};TEM_159_S{:,channel};TEM_284_S{:,channel}];
%% main loop
[x1s,y1s] = mysmoother(x1,y1);
[x2s,y2s] = mysmoother(x2,y2);
figure
plot(x1,y1,'*r',x1s,y1s,'g',x2,y2,'*b',x2s,y2s,'y','LineWidth',4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [xc,ys] = mysmoother(x,y)
% take unique values
[x,ia,~] = unique(x);
y = y(ia);
% my smoother
N = 100;
xi = linspace(min(x),max(x),N); %
% create median average in each bin
for k=1:N-1
ind = (x>=xi(k) & x<xi(k+1));
xc(k) = (xi(k) + xi(k+1))/2;
yc(k) = median(y(ind));
end
% add first and last points (assumed to be in a "clean" area)
xc = [x(1) xc x(end)];
yc = [y(1) yc y(end)];
% smooth it
ys = smoothdata(yc,'rloess',round(N/3));
end
  댓글 수: 4
Zeynep Ertekin
Zeynep Ertekin 2024년 7월 4일
I do not know, how to thank enough. I see that you named the columns as channel to simplfy the stuff.
You are the best.
Wish you success and goodness all the time (fingers crossed)
Mathieu NOE
Mathieu NOE 2024년 7월 5일
Tx for the nice comments , but I still have to work hard if I want to access the top10 league !!!
have a great day !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by