MATLAB Answers

Import Excel-Sheet and plot time - error!

3 views (last 30 days)
Seher Ay
Seher Ay on 4 Feb 2019
Edited: YT on 4 Feb 2019
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!

Answers (1)

YT on 4 Feb 2019
Edited: YT on 4 Feb 2019
This will do the job
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`
If you want to display the values with all decimals in the command window use
format longG
%>> 0.00145743

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!