开发者

Plot behavior of values in a graph

I have a file in the following format with a set of floating-point values:

a1 b1 c1
a2 b2 c2
---end-of-run-1
a1 b1 c1
a2 b2 c2
a3 b3 c3
a4 b4 c4
a5 b5 c5 
---end-of-run-2
...
...
...
till n runs

I want to show this开发者_JS百科 set of columns (i.e. comprising of a,b,c) as different curves on a graph. Also, number of values collected for each run will vary.

Which in-built functions can I use in matlab to determine the behavior of this set of values(a, b, c) over some n runs in a graph?


Quick and dirty, but I would go line by line through the file.

function out = read_and_plot

fid = fopen('input.txt');

line_value = fgetl(fid);
i = 0;
while ischar(line_value)
     if strncmp('--end-of',line_value,8) % we need to start on the next run
        figure;
        plot_data = [col1' col2' col3'];
        plot(1:i', plot_data);
        legend('col1', 'col2', 'col3');
        % clear and restart
        i = 0;
        col1 = []; col2 = []; col3 = [];
     else % we have a line of data
        i = i + 1;
        data = sscanf(line_value, '%f %f %f');
        [col1(i),col2(i),col3(i)] = deal(data(1), data(2), data(3));
     end
     line_value = fgetl(fid);
end

fclose(fid);

return

Now, in order to determine the behavior of the values it would depend if you trying to curve fit or fit a distribution, if so I would recommend the curve fitting toolbox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜