Generate mid values for plotting a smooth line chart in MATLAB

149 Views Asked by At
x = [010,001;    080,310;    080,475;    080,575;...
     110,650;    045,000;    045,550;    045,625;    045,700;...
     045,775;    045,850;    110,870;    110,001;    001,000];

The fisrt column is for the duration in seconds and the second column shows the temperature. I want to plot this data's chart.

This data tells us that

the device had 1 C during 0-10 seconds and heated up to 310 C starting from the 11th second to 90th second. And goes like that.

What I want is to fill between two values linearly in order to see a smooth change.

What I have tried is this:

y=[];
[rx,cx] = size(x);
t = 1;
increment=0;
ii = 1;
row= 0;


for i = 2:rx
    row= row + x(i,2);
    increment = abs( (row- x(ii,2)) / (x(i,1) - x(ii,1) ) );
    for j = 1:x( i, 1 )

        y(t) = increment + x( i, 2 );
        t = t + 1;
    end
    ii = i - 1;
end

plot (y);

and get that:

Plotted data

I want to have a y array like that:

y = [0, .1112, .2223, .3334, .4445, .5556, .6667, .7778, .8889, 1,  .... ]
1

There are 1 best solutions below

0
On BEST ANSWER

After a little thinking, I could have found the way. Here the final code:

clear all;
x = [...
     000,000;... %assuming initial value as zero.   
     010,001;...    
     080,310;...   
     080,475;...    
     080,575;...
     110,650;...    
     045,000;...    
     045,550;...    
     045,625;...    
     045,700;...
     045,775;...    
     045,850;...    
     110,870;...    
     110,001;...    
     110,000 ...
    ];

y=[];
[rx,cx] = size(x);
t = 1;
ii = 1;

for i = 2:rx
    ii = i - 1;
    temp = linspace(x(ii,2),x(i,2),x(i,1));
    [tr, tc] = size(temp);

    for j=1:tc
        y(t) = temp(j);
        t = t + 1;
    end
end

plot(y);