How to remove <missing> from a cell array, possibly replace with blank space

조회 수: 4 (최근 30일)
Gaurav Kumar
Gaurav Kumar 2019년 1월 12일
댓글: Gaurav Kumar 2019년 1월 12일
Originally I imported text (mixed numeric and alphabets/strings) from a file as a table data.
Since the amount of text/data in different lines of the file is different, many of the elements in the table are NaN.
Now I want to write certain specific lines of this table to another file, but I don't want NaN to be written, instead just leave blank space there
What I tried:
fin = strcat(path_in,'/test.txt'); %input filename
file_data = readtable(fin) ; % read data from the file "fin"
bonds_text= (table2cell(file_data(191:end,:)));
bonds_text(cellfun(@isnan,bonds_text,'UniformOutput',false)) = {[]};
When I try to perform the last line operation, which is to remove NaN by a blank space, it gives me the following error:
Function 'subsindex' is not defined for values of class 'cell'.
I am attaching the file from which I am reading the data
Can you please help me fix this error, or is there another better/simpler way of doing this?
Thank you
  댓글 수: 3
Gaurav Kumar
Gaurav Kumar 2019년 1월 12일
Thank you very much Walter.
I had actually tried doing the same earlier, and it was giving me an error, but now I corrected my mistake there.
bonds_text= fillmissing(bonds_text,'constant',''); % wrong, single quote, not a string
bonds_text= fillmissing(bonds_text,'constant',""); % correct, double quote, a string

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by