How to merge and smooth multiple curves in a plot, if there are discrete points?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zeynep Ertekin
el 29 de Jun. de 2024
Comentada: Mathieu NOE
el 5 de Jul. de 2024
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 comentarios
Image Analyst
el 30 de Jun. de 2024
@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.
Respuesta aceptada
Mathieu NOE
el 2 de Jul. de 2024
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 comentarios
Mathieu NOE
el 5 de Jul. de 2024
Tx for the nice comments , but I still have to work hard if I want to access the top10 league !!!
have a great day !
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Preprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!