Hello Guys,
my problem is that I have several data sets of different x-Arrays and always the same y-Array. Basically my plot functions looks like this: plot(x1,y,'g',x2,y,'b'....)
As I have drawn in the picture I want to merge all the lines as to always keep the lowest y-values going from left to right in terms of x-values. This should creat one single new plot that looks like the black line in the right picture. The left picture demonstrates the overlapping data sets.
Can I solve this problem graphically, e.g. using a plotting function to always display the lowest y-value or do I need to create a new 2D array that always picks the lowest y-value for every x- value? Maybe you can give me a base to start from. Sorry about my "untechnical" explanation, Im new to Matlab and coding in general.
Thanks in advance for your support. Pat

2 Kommentare

Guillaume
Guillaume am 18 Okt. 2014
It looks like you meant to attach or (better) embed a figure, but seems like you forgot
Patrick
Patrick am 20 Okt. 2014
Thanks Guillaume,
just attached the image.
Regards Pat

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Guillaume
Guillaume am 20 Okt. 2014
Bearbeitet: Guillaume am 20 Okt. 2014

0 Stimmen

I would concatenate all your x, get the unique values and their position and use the position with accumarray to get the minimum of y:
xall = [x1 x2 x3 ...];
[x, ~, indices] = unique(xall);
y = accumarray(indices, repmat(y, 1, N)', [], @min); %where N is the number of xi
plot(x, y);
edited for missing comma

10 Kommentare

Hi Guillaume,
thanks for your reply. This code:
figure(2)
nall = [n1 n2 n3 n4 n5 n6 n7 n8 n9 n10];
[n, ~indices] = unique(nall);
bcr = accumarray(indices, repmat(bcr,1,N)',[],@min);
plot(n,bcr)
delivers this error message:
Error: File: StabilityLobes.m Line: 67 Column: 5 An array for multiple LHS assignment cannot contain expressions.
Do you have an idea what could be wrong? Regards Pat
Guillaume
Guillaume am 20 Okt. 2014
Yes, I forgot a comma between the ~ and indices. I've edited the answer.
Okay, that solves this error :) Now:
figure(2)
nall = [n1 n2 n3 n4 n5 n6 n7 n8 n9 n10];
[n, ~, indices] = unique(nall);
bcr = accumarray(indices, repmat(bcr, 1, N)', [], @min); %where N is the number of xi
plot(x, y);
I get this error, as N has not be defined I think (Did you assume I kept the definition from Rick so that N = [n1 n2 n3...] ? I rather used your definition of nall = [n1 n2 n2...]. So in the repmat command, what does N need to be?
Regards Pat
Guillaume
Guillaume am 20 Okt. 2014
As the comment says, it's the number of xi, in your case 10.
figure(2)
N = 10;
nall = [n1 n2 n3 n4 n5 n6 n7 n8 n9 n10];
[n, ~, indices] = unique(nall);
bcr = accumarray(indices, repmat(bcr, 1, N)', [], @min); %where N is the number of xi
plot(x, y);
Delivers:
Error using accumarray Second input VAL must be a vector with one element for each row in SUBS, or a scalar.
Error in StabilityLobes (line 69) bcr = accumarray(indices, repmat(bcr, 1, N)', [], @min); %where N is the number of xi
Sorry, I really don't know what to do :/
What is
size(indices)
and
size(repmat(bcr, 1, N)')
They should match.
Unfortunately, they do not match. Here is my code if that helps:
kcb = 1345,618472;
for i=1:length(f); % Sortiere alle Einträge der Frequenz
if ReG(i)<0; % und des Realteils nach Realteil < 0
ReG(i) = ReG(i); % und erstelle neue Vektoren für Realteil
else ReG(i) = 0; % und Frequenz
end;
end;
n1 = 60.*f./(1-1./pi.*atan(ReG./ImG));
n2 = 60.*f./(2-1./pi.*atan(ReG./ImG));
n3 = 60.*f./(3-1./pi.*atan(ReG./ImG));
n4 = 60.*f./(4-1./pi.*atan(ReG./ImG));
n5 = 60.*f./(5-1./pi.*atan(ReG./ImG));
n6 = 60.*f./(6-1./pi.*atan(ReG./ImG));
n7 = 60.*f./(7-1./pi.*atan(ReG./ImG));
n8 = 60.*f./(8-1./pi.*atan(ReG./ImG));
n9 = 60.*f./(9-1./pi.*atan(ReG./ImG));
n10 = 60.*f./(10-1./pi.*atan(ReG./ImG));
bcr = 1./(2.*kcb.*abs(ReG).*1000) % Formel der Grenzspanungstiefe und
for j=1:length(f);
if bcr(j) < 10^10;
bcr(j) = bcr(j);
else bcr(j) = 0;
end;
end;
for k=1:length(f);
if bcr(k)< 10^(-10);
n1(k) = 0;
n2(k) = 0;
n3(k) = 0;
n4(k) = 0;
n5(k) = 0;
n6(k) = 0;
n7(k) = 0;
n8(k) = 0;
n9(k) = 0;
n10(k) = 0;
end;
end;
bcr = nonzeros(bcr);
n1 = nonzeros(n1);
n2 = nonzeros(n2);
n3 = nonzeros(n3);
n4 = nonzeros(n4);
n5 = nonzeros(n5);
n6 = nonzeros(n6);
n7 = nonzeros(n7);
n8 = nonzeros(n8);
n9 = nonzeros(n9);
n10 = nonzeros(n10);
figure(1)
plot(n1,bcr,'b',n2,bcr,'r',n3,bcr,'y',n4,bcr,'m',n5,bcr,'m',n6,bcr,'g',n7,bcr,'k',n8,bcr,'b',n9,bcr,'r',n10,bcr,'y')
title('Stabilitätskarte')
xlabel('Drehzahl n [1/min]')
ylabel('Grenzspanungstiefe bcr [mm]')
figure(2)
nall = [n1; n2; n3; n4; n5; n6; n7; n8; n9; n10];
[n, ~, indices] = unique(nall);
bcr = accumarray(indices, repmat(bcr, 1, 10)', [], @min);
plot(x, y);
Here are the dimensions of the Variables:
f 201 x 1
ReG 201 x 1
bcr 197 x 1
ImG 201 x 1
n1 to n10 197 x 1
nall 1970 x 1
Do you have any other ideas how I can progress with my script?
Thanks a lot for your help so far. I hope we can solve this together Regards Pat
Ok, I assumed your ni and bcr were row vectors, whereas they're column vectors.
You've already concatenated your ni by column so that's good, but you need to do the same with the repmat'ed bcr:
bcr = accumarray(indices, repmat(bcr, 10, 1), [], @min);
Note that while the code does what you asked, that is keep the lowest y-values going from left to right in terms of x-values, the result may or may not be what you expect. It's possible that the x values in each of your n arrays do not intersect, that is one is x, the other x + very small delta. As a result, no y has a common x so the final function will just be very noisy.
Patrick
Patrick am 26 Okt. 2014
Thanks for your reply, I will see what the results might be, but I get your point with the noise. That's the reason I was looking for a graphical approach to my problem in the first place. Do you know of any other mehtod tol realize what I pointed out in the attached image?
Patrick
Patrick am 27 Okt. 2014
Okay, I put the resulting diagram into the attachment. For my purpose the occurring noise is not really significant. Thanks a lot for your help, Guillaume!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Rick Rosson
Rick Rosson am 18 Okt. 2014

1 Stimme

x = [ x1 x2 x3 ... ];
N = length(x)/length(y);
y = repmat(y,1,N);
plot(x,y);

2 Kommentare

Patrick
Patrick am 20 Okt. 2014
Hello Rick,
thanks for your answer! It gives me the same results as my previous code though:
figure(1) plot(n1,bcr,'b',n2,bcr,'r',n3,bcr,'y',n4,bcr,'m',n5,bcr,'m',n6,bcr,'g',n7,bcr,'k',n8,bcr,'b',n9,bcr,'r',n10,bcr,'y')
VS:
figure(2) n = [n1 n2 n3 n4 n5 n6 n7 n8 n9 n10]; N = length(n)/length(bcr); bcr = repmat(bcr,1,N); plot(n,bcr)
However, I dont want 10 individual graph lines in one diagram. What I need is one single united line that always displays Ymin(n), like I have scatched in the pictures attached.
Oops, sorry about that attachment. Forgot to hit the "Attach file" button.
vi trung kien
vi trung kien am 21 Mär. 2018
Bearbeitet: vi trung kien am 21 Mär. 2018
Dear Patrick, Can you suggest for me how to get one single united line that always displays Ymin(n), like you have scratched in the pictures attached.My problem the same as you before. Thanks for your help.

Melden Sie sich an, um zu kommentieren.

Tags

Gefragt:

am 18 Okt. 2014

Bearbeitet:

am 21 Mär. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by