필터 지우기
필터 지우기

How can I split up several numbers in one cell from an excel file?

조회 수: 15 (최근 30일)
Dear Matlab-Community,
I want to import an excel file with 9 numbers in one cell separated by a comma. I need this data to be split up and written in 9 columns.
For example:
Input:
0,565.24,18.3882,0,69.1582,0,15.68,0,0
1,582.69,18.3895,0,64.1595,0,15.33,0,0
... and so on.
Could somebody help me with this?
Thanks in advance!
Domi

채택된 답변

Star Strider
Star Strider 2019년 2월 14일
I am not exactly certain what you want.
One option would be the mat2cell (link) function. Each column would be its own cell, so you could then address them easily. Use the first output of xlsread (it should be a numeric matrix).
The code would be something like this:
[D,S] = xlsread('YourFile.xlsx');
ColCells = mat2cell(D, size(D,1), ones(1,size(D,2)));
  댓글 수: 3
Dominik Kümpflein
Dominik Kümpflein 2019년 2월 14일
편집: Dominik Kümpflein 2019년 2월 14일
Yes you are right. It's an csv-file. I'm not used to that and didn't know how to handle it so I converted it to an .xlsx, sorry for that. (Not gonna do that mistake again)
I tried your suggestion with xlsread the csv-file, but the mat D remains empty and so 'ColCells' of course too. But the way with the txt file works perfectly!
Thank you so much!
Star Strider
Star Strider 2019년 2월 14일
As always, my pleasure!

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

추가 답변 (2개)

Dominik Kümpflein
Dominik Kümpflein 2019년 2월 14일
First of all, thanks for your quick answers.
I'm sorry if I didn't made clear enough what I wanna do.
I added a Screenshot of how my Excel-File looks. These are data logged by a GoPro that i extracted from a MP4-File. To do further calculations i need to extract the GPS-Data from it.
Unfortunatly, all data from one timestep is written in one Excel-Cell and separated by a comma. So now I'm looking for a way to read the data in Matlab and split it up, so i get a mat or cell-array with one column for the timestep, one for the Latitude one for the Longitude and so on.
Screenshot_Mathworks_Forum.PNG
  댓글 수: 4
Dominik Kümpflein
Dominik Kümpflein 2019년 2월 14일
Here is my Excel file for the input

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


Bob Thompson
Bob Thompson 2019년 2월 14일
[~,~,data] = xlsread('myexcel.xlsx',range);
data = cellfun(@(x) str2num(x),data);
This is a first crack at the code. I'm not absolutely certain that the cellfun will work as I want it to, since I haven't tested it. Basically, you are going to read all of the cells of the excel file into a matlab cell array. I expect that the cells with multiple numbers will be treated as a string, but using str2num should convert them into actual number arrays for you.

카테고리

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