Calculating average curve

I have 2 different sets of values corresponding to a magnetization curve. My problem is that I cannot actually compute the mean values of the curves. I am thinking I should use some kind of interpolation, but I don't know how.

My code so far:

I = [ 0 1.1 4 9.5 15.3 19.5 23.1 26 28.2 30.8 33.3 35.9];
E_up = [ 5.8 10.5 28 60.3 85.5 100.3 108 113.2 117 120.5 123.5 126];
Iw = [ 34 31.5 28.2 23.9 19.9 16.1 13 8.1 3.5 1.2 0 NaN];
E_down = [124.6 122.5 118.8 112.2 103.9 93.1 81.6 59.1 29.6 14.5 9.5 NaN];
n = 800/1500;

plot(I,E_up,Iw,E_down)
grid on 
legend ('up', 'down')

%loop for mean values

for ii = 1:length(I)
    E1(ii) = ((E_down(13-ii)));
    E2(ii) = E_up(ii);
    E4(ii) = mean([E1(ii),E2(ii)]);
    I2(ii) = Iw(13-ii)
    I3(ii) = mean([I2(ii),I(ii)])
end


hold on     
plot(I3,E4,'r-')
plot(I3(7),E2(7),'co',I3(7),E1(7),'ro')
plot(I3,E1,'c-',I3,E2,'g-')

Here is the graph I am getting and its totally wrong

*edit The problem is I am actually getting the average curve of cyan and light green instead of blue and dark green.

Answers


%// Trump up some curves
tmp = [1:1e3].';%'//
A(:,1) = tmp;
A(:,2) = 2.*tmp;
A(:,3) = 0.5*tmp+1;
A(:,4) = 2.2.*(tmp+0.2);
A(:,5) = 1.3.*tmp;

%// calculate means
B = mean(A,2);
C = mean(A(:,[1 5]),2);

figure;
hold on
plot(A,'b')
plot(B,'r') %// mean of all blue curves
plot(C,'g') %// mean of the top and bottom curves

mean works on matrices and can be set to take the mean per row setting the second input to 2.


Well i have interpolated the one curve and thereafter used mean. So my code is:

clc, clear all, close all;

I = [ 0 1.1 4 9.5 15.3 19.5 23.1 26 28.2 30.8 33.3 35.9];
E_up = [ 5.8 10.5 28 60.3 85.5 100.3 108 113.2 117 120.5 123.5 126];
Iw = [ 34 31.5 28.2 23.9 19.9 16.1 13 8.1 3.5 1.2 0 NaN];
E_down = [124.6 122.5 118.8 112.2 103.9 93.1 81.6 59.1 29.6 14.5 9.5     NaN];
n = 800/1500;

x_est = I;
y_est = spline(Iw,E_down,x_est)
A(:,1)= E_up
A(:,2) = y_est

ma = mean(A,2)

figure()
hold all
plot(I,E_up,'b-',Iw,E_down,'g-')
plot(I,ma,'r')
grid on
legend('up','down','mean')

Need Your Help

Make div expand on hover

html css3 hover scale expand

Basically, I just want to create a "relative" scale up of the div i'm hovering. I tried the following, but the output is a disaster. Help would be appericiated!

How exactly are $_SESSION and $_SERVER variables requested?

php arrays session optimization

I have a simple question: how exactly are array variables such as $_SESSION and $_SERVER requested? Are they simply set when the page is requested and remain the same until the page is requested (e...