MATLAB Answers

Seher Ay
0

Import Excel-Sheet and plot time - error!

Asked by Seher Ay
on 4 Feb 2019
Latest activity Edited by YT
on 4 Feb 2019
Hello,
I have the following Excel-Sheet (attachement). The first column contains the time in the format 'HH:MM:SS' and the second column contains the forxe (integer).
data = xlsread('2018-12-07--15-55-46 - alt_1.csv');
time = data(:, 1);
force = data(:,2)
time_new_format = datestr(time, 'HH:MM:SS')
plot(time_new_format, force)
1. After running this code the following error occurs. "Error using plot Invalid first data argument." I guess because the new time is a string, maybe I must use datenum, but I don't know how.
2. My second problem is, when I want to check the force in the command window by entering "force" then the values are roundet up to 0.0015. Can I pevent Matlab from rounding up these values?
Thank you very much!

  0 Comments

Sign in to comment.

1 Answer

Answer by YT
on 4 Feb 2019
Edited by YT
on 4 Feb 2019

This will do the job
clear;
opts = detectImportOptions('2018-12-07--15-55-46 - alt_1.csv','Delimiter',';');
opts = setvartype(opts,[1],'duration'); %as duration
opts = setvartype(opts,[2],'double');
opts = setvaropts(opts,[2],'DecimalSeparator',','); %your file contains `,` as decimal seperator; matlab uses `.` for decimals
T = readtable('2018-12-07--15-55-46 - alt_1.csv',opts); % read in your file
T = [array2table(seconds(T{:,1})) T(:,2)]; %change the HH:mm:ss time format using `seconds`
plot(T{:,1},T{:,2});
If you want to display the values with all decimals in the command window use
format longG
T{1,2}
%>> 0.00145743

  0 Comments

Sign in to comment.