How can plot multiple same amplitude signals along with same y axis ?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Zara Khan
il 22 Gen 2019
Commentato: Star Strider
il 2 Feb 2019
I am using this code to plot multiple signals. But unable to plot using same y axis. I am some overlapping plot due same amplitude. How to manage them in same figure? Signals will be in dufferent length but later I want to scale them with same length. I am attaching figure that is representing how will be my output.
clc;
close all;
clear;
workspace;
a = imread('img.png');
bwimg =bwareafilt(~a, 1);
s=regionprops(bwimg,'Orientation','Centroid','MajorAxisLength','MinorAxisLength');
circleCenterX =s.Centroid(1);
circleCenterY =s.Centroid(2);
diameters = mean([s.MajorAxisLength s.MinorAxisLength],2);
t=0:0.001:2*pi;
r1 =1*diameters/8;
x = circleCenterX + r1 * sin(t);
y = circleCenterY + r1 * cos(t);
[r,c]=size(bwimg);
bw=false(r,c);
t=0:0.001:2*pi;
bw =bw|poly2mask(x,y,r,c);
boundaries = bwboundaries(bw);
thisBoundary = boundaries{1};
x1=thisBoundary(:,2);
y1=thisBoundary(:,1);
indexes = y1<circleCenterY; % Only those in the upper half.
xTop = x1(indexes);
yTop = y1(indexes);
figure;
for k=1:length(xTop )
profile(k) = bwimg(yTop(k),xTop(k ));
plot(profile,'r-','LineWidth',2 );
%grid on ;
ylim([0 2]);
axis off;
end
r2 =2*diameters/8;
x2 = circleCenterX + r2 * sin(t);
y2 = circleCenterY + r2 * cos(t);
bw =bw|poly2mask(x2,y2,r,c);
boundaries = bwboundaries(bw);
thisBoundary = boundaries{1};
x3=thisBoundary(:,2);
y3=thisBoundary(:,1);
indexes = y3<circleCenterY; % Only those in the upper half.
xTop1 = x3(indexes);
yTop1= y3(indexes);
for k=1:length(xTop1)
profile1(k) = bwimg(yTop1(k),xTop1(k ));
plot(profile1,'b-','LineWidth',2 );
%grid on ;
ylim([0 2]);
axis off;
end
r3 =7*diameters/8;
x4= circleCenterX + r3 * sin(t);
y4= circleCenterY + r3 * cos(t);
bw =bw|poly2mask(x4,y4,r,c);
boundaries = bwboundaries(bw);
thisBoundary = boundaries{1};
x5=thisBoundary(:,2);
y5=thisBoundary(:,1);
indexes = y5<circleCenterY; % Only those in the upper half.
xTop2 = x5(indexes);
yTop2 = y5(indexes);
for k=1:length(xTop2)
profile2(k) = bwimg(yTop2(k),xTop2(k ));
plot(profile2,'r-','LineWidth',2 );
%grid on ;
ylim([0 2]);
axis off;
end
r4 =8*diameters/8;
x5= circleCenterX + r4 * sin(t);
y5= circleCenterY + r4 * cos(t);
bw =bw|poly2mask(x5,y5,r,c);
boundaries = bwboundaries(bw);
thisBoundary = boundaries{1};
x6=thisBoundary(:,2);
y6=thisBoundary(:,1);
indexes = y6<circleCenterY; % Only those in the upper half.
xTop3 = x6(indexes);
yTop3 = y6(indexes);
for k=1:length(xTop3)
profile3(k) = bwimg(yTop3(k),xTop3(k ));
plot(profile3,'b-','LineWidth',2 );
%grid on ;
ylim([0 2]);
axis off;
end
4 Commenti
Jan
il 22 Gen 2019
I do not get any idea, how the attached images concern the described problem. You have posted a pile of code, but it is not clear, which lines are interesting to understand, what you want to achieve. Does "cant separate all the signals" mean, that you want to separate some signals? Please elaborate this again. I know, that it is hard to do this in a foreign language, but don't give up. Explain the problem, until somebody understands it and support you to find a solution.
Risposta accettata
Star Strider
il 22 Gen 2019
Modificato: Star Strider
il 22 Gen 2019
x = linspace(0, 2*pi); % Independent Variable
y = sin((0:5)'*x); % Original Signals
y = bsxfun(@plus, y, (0:size(y,1)-1)'*2); % Separated Signals
figure
plot(x, y)
grid
EDIT —
Added plot:
21 Commenti
Star Strider
il 23 Gen 2019
Then just do something like this:
profile_a = profile;
profile1_a = profile1 + 2;
prodile2_a = profile2 + 4;
profile3_a = profile3 + 6;
Then plot ‘profile_a’ and the others, instead.
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!