How to remove NaN values from an array

3 ビュー (過去 30 日間)
Alex
Alex 2019 年 4 月 23 日
コメント済み: Star Strider 2019 年 4 月 25 日
I have an array 'AllTEC' of measurements from different sensors at different latitudes 'Latrayend' (see attached test.mat). Each column in 'AllTEC' and 'Latrayend' is from a different sensor. I plot these as different color lines but a gap occurs where there are NaN values:
I want the lines to be continuous. For one sensor (a vector) I simply use:
%find and remove nan values
Latrayend(find(isnan(AllTEC)))=[]
AllTEC(find(isnan(AllTEC)))=[]
%plot figure 3
cmap = jet(m);
figure
for k=1:m
line(Latrayend(:,k),AllTEC(:,k), 'Color', cmap(k, :)), hold on% USE FOR LARGE NUMBER OF
ylabel('Total Electron Content (TECu = 10^{16} electrons/m^2)','fontsize',24, 'fontweight','bold')
xlabel('Satellite Latitude (Degree)','fontsize',24, 'fontweight','bold');
title('FIG 3- STEC as a function of satellite latitude')
end
legend(h)
hold off
But this does not work for an array. I tried doing this within the loop to create the figure, but get a subscript assignment mismatch error. I understand it is because the array would then not have the same order (when the loop goes through the first vector there are empty cells, but i don't care if it is an array of columns with different lengths. In this case I could just delete the entire row, but this may not be the case for futre datasets.
Thank you in advance for your help!
best regards,
Alex

採用された回答

Star Strider
Star Strider 2019 年 4 月 23 日
Since you want the lines to be continuous, consider using the fillmissing (link) function to fill in the NaN values with numbers. (It was introduced in R2016b.)
  6 件のコメント
Alex
Alex 2019 年 4 月 25 日
Great! Thank you!
Star Strider
Star Strider 2019 年 4 月 25 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeReference Applications についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by