Replace missing values by 0
古いコメントを表示
Hello everybody
I importing some .txt data from Bloomberg to Matlab. The problem is that in some cases there is a value missing in my .txt file and Matlab stops reading. I would love to automatically replace empty values (cells) in my .txt file by 0's so that Matlab keeps reading.
I attach the file I want to import and the code. As you will see there is a missing value in line 45 column H. Matlab stops reading exactly in that place and delivers "Subscripted assignment dimension mismatch". .
I hope you can help me.
Best regards
fid = fopen( ['file1.txt'] );
N_beg = 8;
N_end = 49;
Data = zeros(44,5); %44 = 10 years and 4 quartely results per year
for i = 1 : N_end
tline = fgets(fid);
if(i >= N_beg)
ii = i-N_beg + 1;
A = strsplit(tline,'/');
AA = strsplit(A{1,3});
B = strsplit(A{1,4});
C = A{1,4};
D = B{1,4};
for j = 1 : 2;
Data(i-N_beg+1,j) = str2num(A{1,j});
end
Data(i-N_beg+1,3) = str2num(AA{1,1});
Data(i-N_beg+1,4) = str2num(B{1,2});
Data(i-N_beg+1,5) = str2num(D); %Earnings surprise
end
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!