Alias blanks in the cell array as a string.
이전 댓글 표시
I am using the ‘importdata’ function to read a text file. It reads the numeric data as a matrix and text data as a cell array; now the first element of cell array is all the headers, I use a ‘strsplit’ function to separate each individual variable name in header. The issue is that there are some blank columns in the text file, so the numeric matrix reads it as a ‘NaN’ but the resulting variables (which I used ‘strsplit’ for) eliminates blanks. Now the result is that size(textdata,2) +size(data,2) is not equal to size(variable,2). I want to read blanks in the header as a variable, alias it as ‘empty’

댓글 수: 5
Viraj Sabane
2025년 1월 31일
편집: Walter Roberson
2025년 1월 31일
Viraj Sabane
2025년 1월 31일
dpb
2025년 1월 31일
"I am using the ‘importdata’ function to read a text file..."
There's the root problem. importdata, while handy from a simple syntax standpoint tends to create more trouble than it solves as you discovered. I'd recommend using readtable instead and you'll have both variables handled by name by their proper type in a single table variable. You can customize how things are imported regarding the missing columns per your requirements with either some additional named variable options or by the use of an import object via detectImportOptions
Stephen23
2025년 1월 31일
I second dpb's comment: avoid IMPORTDATA, use READTABLE or TEXTSCAN or the like.
Viraj Sabane
2025년 2월 3일
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Data Import and Export에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

