readcell vs xlsread: substitute "1x1 missing" with "NaN"

22 ビュー (過去 30 日間)
JarryG
JarryG 2022 年 5 月 12 日
コメント済み: JarryG 2022 年 5 月 12 日
I used to import my mixed (char/num) content from xls-files as cell array with:
[~, ~, raw1] = xlsread(myfile, mysheet, myrange, 'basic')
Because xlsread is "not recommended", I'm trying to move to readcell. So according to "compatibility consideration" in documentation, I'm now using:
raw2 = readcell(myfile, 'Sheet', mysheet, 'Range', myrange);
It works, but where I had "NaN" in raw1, now I see "1x1 missing" in raw2. I'd like to replace those "1x1 missing" with "NaN" to get the very same output as with xlsread, so I tried:
raw2(cellfun(@(x) any(ismissing(x)), raw2)) = {NaN};
The problem is, not only "1x1 missing", but also some (but not all) valid text values are replaced. What am I doing wrong?
  2 件のコメント
Jan
Jan 2022 年 5 月 12 日
It would be much easier to find the problem, if we have the input data or know, which data are unexpectedly replaces. "Some bit not all" does not reveal the details.
JarryG
JarryG 2022 年 5 月 12 日
Wow, you actually helped me! I checked what data were replaced, and it was not so random as I thought. Only strings with empty characters like "test string" were replaced, while others like "test-string" were not. It seems "any" statement in my cell function is incorrect, as empty character is evaluated as "missing", and it is enough if single one is found. So I changed my function to:
raw2(cellfun(@(x) all(ismissing(x)), raw2)) = {NaN};
Now it works as expected: all "1x1 missing" are replaced by "NaN", and nothing else...

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by