1
votes

I have a data set

10 4.567
20 3.287
30 4.990
40 3.333
50 3.889
10 4.566
20 3.001
30 4.990
40 3.331
50 3.886
.
.
.

20 sets like this downwards. I want to plot this in matlab but plotting creates horizontal lines as the values in the x are taken as continuous. Any help is highly appreciated.

2

2 Answers

3
votes

Use a loop:

figure(1), clf, hold on
for ii = 2:size(data,2)
    plot(data(:,1), data(:,ii))
end

Now, you might want to add a bit of colour:

colours = {...
    'r--', 'g--', 'b--', 'k--', 'm--', 'c--', ...
    'r.-', 'g.-', 'b.-', 'k.-', 'm.-', 'c.-', ...
    'rs-', 'gs-', 'bs-', 'ks-', 'ms-', 'cs-', ...
    'rt-', 'gt-'});
figure(1), clf, hold on
for ii = 2:size(data,2)
    plot(data(:,1), data(:,ii), colours{ii})
end
0
votes

Reform your data to give one set of x values and several sets of y values. This assumes the x values are the same each time.

If you have repeated sets of 5 values (as in your example), then n=5 in the code below:

d = [10 4.567
20 3.287
30 4.990
40 3.333
50 3.889
10 4.566
20 3.001
30 4.990
40 3.331
50 3.886]

n = 5;
x = d(1:n, 1);
y = reshape(d(:,2),n,[])
plot(x,y) % Plot each set of y values separately