readcell is filling cell locations with "1x1 missing"

조회 수: 129 (최근 30일)
David Teitge
David Teitge 2019년 5월 31일
댓글: Stephan Piotrowski 2022년 1월 21일
I am using R2109a and it is recommended to use readcell instead of xlsread. Readcell is slower than xlsread and it is returning "1x1 missing" instead of an empty cell when reading an .xlsx file. I don't know what logical I can use to remove these cell locations without brute forcing the problem. Does anyone else know what I can do to fix this?
Capture.PNG
  댓글 수: 2
Josef Shaoul
Josef Shaoul 2020년 1월 11일
The other answers did not work for me. readtable was very slow, and the cellfun(missing...) solution gave empty columns.
The simple, stupid solution is use readcell (faster than xlsread) and just a double loop over the raw cell data to convert <missing> to NaN. That yielded the same result as xlsread.
Would be ven better if the next version would restore the result from xlsread to readcell, because now the cell array that is imported cannot be saved again in an Excel file!
Stephan Piotrowski
Stephan Piotrowski 2022년 1월 21일
@Josef Shaoul I experienced extremely slow readtable, but found that calling it as readtable(input,'basic',true) greatly improved the performance.

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

채택된 답변

Guillaume
Guillaume 2019년 6월 4일
If your data (excluding header) is purely numeric, you'd be better off using readmatrix instead of readcell. If your date is heterogeneous you'd be better off using readtable. The matrix/table will use less memory than a cell array and more crucially make it very easy to remove rows with <missing> entries with rmmissing.
t = rmmissing(readtable(youfile))
With a cell array, rmmissing will only work if the cell array only contain char vectors.
  댓글 수: 1
David Teitge
David Teitge 2019년 6월 6일
Thanks! I had to use readtable, and it does run a lot faster!

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

추가 답변 (1개)

Jon Martinez
Jon Martinez 2019년 6월 4일
I've had the same problem reading a CSV file and managed to substitute all missing cells with this command:
your_file = readcell(your_path);
your_file(cellfun(@(x) any(ismissing(x)), your_file)) = {''};
The cellfun command will give you a logical array that mantains the structure of the original cell array. Hope it helps.
  댓글 수: 2
David Teitge
David Teitge 2019년 6월 6일
Thanks! I did not try your answer because the other answer suggested using another function which works better than readcell. I still appreciate it!
Ning
Ning 2022년 1월 5일
Thanks!

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by