Import of mixed string and numerical data from excel file
조회 수: 4 (최근 30일)
이전 댓글 표시
I am currently trying to import data from an Excel file. The data typically looks like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157612/image.png)
So far I have been dealing with only numerical tables with a limited number of arrays, but now I need to find certain data in large tables and prefer to automate the process a bit. In this regard I have a few problems with the import from Excel: 1. How can I read the column titled "Date & Time" as a string and convert its values into a numerical values? I already know that MATLAB can handle specific date and time formats and this seems to be outside of that format. 2. I want MATLAB to identify each column with the title stated in the first line (power, T, rpm etc.) so it can e.g. always know where the "force" data is stored and treat it accordingly? 3. How can I tell MATLAB to recognize the command * "Start Here"* in location (A11) so that I can e.g. start a certain calculation from this point on?
Thanks Saeid
댓글 수: 0
채택된 답변
Mostafa
2016년 11월 2일
I believe that the easiest (not the fastest) way is to import all the data at once in matlab environment then process it there.
DataSet = xlsread(fileName);
Analyze the first row of the imported data set: Search for certain strings, assign variables to the indicies of each data column (Power, T, rpm, force,..), and use these variables to deal with the rest of the data set.
IdxDate = find(cellfun(@(X) strcmp(X,'Date & Time'), DataSet(1,:)));
IdxPower = find(cellfun(@(X) strcmp(X, 'power'), DataSet(1,:)));
IdxForce = find(cellfun(@(X) strcmp(X, 'force'), DataSet(1,:)));
...
Analyze the first column of the imported data set: Search for the string "Start here" and start accessing the data set from this point.
IdxStart = find(cellfun(@(X) strcmp(X,'Start Here'), DataSet(:,1)));
%%Data of concern inside the power column
DataPower = DataSet(IdxStart:end, IdxPower);
%%Data of concern inside the force column
DataForce = DataSet(IdxStart:end, IdxForce);
%%Simple calculation
SomeValue = cellfun(@(X,Y) str2double(X)*str2double(Y), DataForce, DataPower);
%%Or if the data is parsed as numbers and not strings:
%%SomeValue = cellfun(@(X,Y) X*Y, DataForce, DataPower);
...
I'm not really sure what you mean by converting the date into numerical values, but you can use a similar notation.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 String에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!