Import Excel-Sheet and plot time - error!

조회 수: 1 (최근 30일)
Seher Ay
Seher Ay 2019년 2월 4일
편집: YT 2019년 2월 4일
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!

답변 (1개)

YT
YT 2019년 2월 4일
편집: YT 2019년 2월 4일
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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by