MATLAB Answers

0

How to open .CSV file ?

Asked by Vishu Dhakad on 13 Jun 2018
Latest activity Answered by Walter Roberson
on 15 Jun 2018

I want to open CSV file. (please find the attachment)

in the CSV file, I have date and time in the different column but I want to combine in one column. I have read with following code but I getting an error.

fbc = fopen('ABCD.CSV');

BC = textscan(fbc, '"%.f-%3.s-%.f", "%.f:%.f", %.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f');

fclose(fbc);

  0 Comments

Sign in to comment.

2 Answers

Answer by KSSV
on 13 Jun 2018

[num,txt,raw] = xlsread('ABCD.csv') ;

  1 Comment

Thank you, sir

but time is showing in decimal, how to correct into normal?

I want to use the function fopen and textscan.

Can you explain to me how to use this type of function?

Sign in to comment.


Answer by Walter Roberson
on 15 Jun 2018

fmt = ['%{dd-MMM-yy}D%{HH:mm}D', repmat('%f', 1, 50)];
fbc = fopen('ABCD.CSV', 'r', 'n', 'UTF8');
BC = textscan(fbc, fmt, 'Delimiter', ',', 'CollectOutput', 1);
fclose(fbc);
dt = BC{1}+(BC{2}-dateshift(BC{2},'start','day'));
dt.Format = 'default';
numbers = BC{3};

  0 Comments

Sign in to comment.