필터 지우기
필터 지우기

cell to double using cell2mat

조회 수: 4 (최근 30일)
Dylan Mecca
Dylan Mecca 2018년 2월 12일
댓글: Star Strider 2018년 2월 12일
Hi everyone,
I'm looking to take a variable from a spreadsheet I import to be plotted. I've done some poking around and found that you cannot plot a cell style import of data and needs to be converted to double. So I used the cell2mat command, but the return was char. I don't know what this means, but it is still giving me errors when I try to plot.
A = cell2mat(Time)

채택된 답변

Star Strider
Star Strider 2018년 2월 12일
I’m guessing here, because I don’t have an example of your data.
Dates and times are frequently imported as character arrays. The easiest way to import them is as a datetime (link) array (in R2014b and later releases). You can then work with them and convert them to date numbers if necessary.
The other fields of your data you can use with cell2mat if necessary.
  댓글 수: 2
Dylan Mecca
Dylan Mecca 2018년 2월 12일
I've attached a sample of the data my project is using. I am using 2014a unfortunately. Do you have another suggestion for converting this data to double? My first inclination is to use cell2mat but it returns my data as char. Do you know of another conversion, possibly, to change char to double?
Star Strider
Star Strider 2018년 2월 12일
I use xlsread to read the file. This code produces the correct date numbers, that you can then use as you wish in your code:
[d,s,r] = xlsread('20180122Mx00_Go-Stop CE(US)0001.CSV');
DateN = datenum(s(2:end,1), 'yyyy-mm-dd');
The first row of ‘Date’ is the word 'Date' itself, so it is necessary to begin with row 2. I am not certain what the ‘Time’ data represent. If they are decimal fractions of a day, just add them to ‘DateN’, since that is how date numbers operate in MATLAB. If they represent something else, you will have to convert them into fractions of a day, first, beofre adding them to ‘DateN’.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by