1
votes

I am trying to get the my data read through Matlab and then plot it, but with my code using fscanf and/or textscan the file is being read as one array and taking the data one by one as a character which makes it impossible to plot. It's like each char/integer is an array. Here's how my data looks like:

Time        Volt     Chan 1  chan 2   chan 3    chan 4   chan 5     chan 6   chan 7
3333.222        222.33   0.2334  0.3444   0.2233    0.4455   -0.733     0.3333   0.12345
3333.222        0.2323   0.4566  0.3456   0.2453    0.4563   -0.753     0.2356   0.23455

I want to plot the time data Versus the volts and the other channels separately. Can Anyone help? I know the data looks wrong on here but there's two set of data for each channels.

1
is the txt file formatted in the way you reported? or in a standard tabular way with any variable as header and the associated values as attributes? - fpe
Why don't you update your question with a screen shot of input data sets and expected (manual) output. That would really help and call me visual :D - bonCodigo

1 Answers

0
votes

it seems like that apart from the first row, the rest of the file is quite ordered. Try read the first line using fgetl, and then the rest of the lines using textscan Something like:

fid = fopen( filename );
firstLine = fgetl( fid );
C = textscan( fid, '%f', 9 );
volt = [];
tm = [];
ch = zeros(0, 7);
while ~isempty(C{1})        
    volt( end + 1 ) = C{1}(1);
    tm( end + 1 ) = C{1}(2);
    ch( end + 1, : ) = C{1}(3:end)';
    C = textscan( fid, '%f', 9 );
end
figure;
plot( tm , volt ); title('volt vs time');
figure;
plot( tm, ch ); legend({'c1', 'c2', 'c3', 'c4', 'c5', 'c6', c7'});
title('chnnels vs time');