How to adjust the "isnan" to make it work for cell?

1 回表示 (過去 30 日間)
Ismail Qeshta
Ismail Qeshta 2018 年 2 月 20 日
コメント済み: Ismail Qeshta 2018 年 2 月 21 日
Hi I have the below for loop. I would like to replace the NaN data output with 0.07. I keep getting the below error message. Could anyone please advise me how to stop the error message? Thank you.
for i=1:size(A,2)%number of columns
x{i} = interp1(y3, x3, A(:,i), 'linear');
k=1:1;
temp=x(k,:);
temp(isnan(temp))=0.07;
x(k,:)=temp;
fid=fopen(['result_' num2str(1) '.txt'],'w');
fprintf(fid,'%f\n',x);
fclose(fid);
end
The error message:
Undefined function 'isnan' for input arguments of type 'cell'.
Error in InterpolaeMFJavadCompleted (line 24)
temp(isnan(temp))=0.07;
  1 件のコメント
Birdman
Birdman 2018 年 2 月 20 日
Check Stephen's answer.

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

採用された回答

Stephen23
Stephen23 2018 年 2 月 20 日
編集済み: Stephen23 2018 年 2 月 20 日
Don't waste your time with cell arrays and cell2mat and the like, you don't need them. Just use a numeric variable:
N = size(A,2) %number of columns
%C = cell(1,N);
for k = 1:N
tmp = interp1(y3, x3, A(:,k), 'linear');
tmp(isnan(tmp))=0.07;
%C{k} = tmp;
fnm = sprintf('result_%d.txt',k);
[fid,msg] = fopen(fnm,'wt');
assert(fid>=3,msg)
fprintf(fid,'%f\n',tmp);
fclose(fid);
end
I also made some other small changes to make your code more robust.
  25 件のコメント
Jan
Jan 2018 年 2 月 21 日
@Ismail: If the answer solves your problem, please accept it.
Ismail Qeshta
Ismail Qeshta 2018 年 2 月 21 日
Done :-) Thanks Jan.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by