필터 지우기
필터 지우기

Plotting vectors with different lengths due to missing values

조회 수: 5 (최근 30일)
Jonas Joubert
Jonas Joubert 2017년 7월 10일
댓글: Kelly Kearney 2017년 7월 11일
I have sets of data that I need to plot against each other, the problem is that some of the data points are present in one set but were not recorded in another (same sample but different type of data) I was wondering if there was any way for when one data point is not present (I have denoted this with a % on the lines without data) to discard the other data points from that sample. Currently MATLAB is just ignoring the data line with the % and plotting data points against each other that are not from the same sample. I hope this is clear enough. Cheers in advance

답변 (1개)

Kelly Kearney
Kelly Kearney 2017년 7월 10일
Can you give a small sample of your data? Is it manually entered in a script, or are you reading it in from a file?
In general, you can use NaNs as placeholders for missing data. But the best way to do this will depend on the exact format of your data.
  댓글 수: 2
Jonas Joubert
Jonas Joubert 2017년 7월 11일
I'm reading the data from a file. Here's two examples of the data files I'm using, as you can see the ammonia file is missing data from samples 19 and 23. This is the code I'm using to read in the data as well
function [d,mean,SE] = freadavonboatdata(infile)
data = load(infile);
d = data(:,2);
mean = data(:,3);
SE = data(:,5);
n = length(d);
end
end
Kelly Kearney
Kelly Kearney 2017년 7월 11일
Well, that can't be the exact code you're using to read in those files... load will fail (or at least, only read part of the file) if you have text fields like 'NO DATA' mixed into your data.
In this case, I'd use a table array to read in the data; readtable can handle missing data pretty well, and the table join command makes it easy to combine two datasets that share a common key variable (in this case, Sample).
files = {...
'~/Downloads/Ammonia.txt'
'~/Downloads/Conductivity.txt'};
nfile = length(files);
tbl = cell(nfile,1);
for ii = 1:length(files)
tbl{ii} = readtable(files{ii}, 'headerlines', 1, 'treatasempty', 'NO DATA');
isemp = isnan(tbl{1}.Sample);
tbl{ii} = tbl{ii}(~isemp,:);
end
A = join(tbl{1}, tbl{2}, 'keys', 'Sample');
Once all your data is in the table, you can plot it easily, either with or without the Sample numbers that include missing data.
subplot(2,1,1);
[~, hln(1), hln(2)] = plotyy(A.Sample, A.Mean_left, A.Sample, A.Mean_right);
set(hln, 'marker', 'o');
title('Missing data points included (as NaNs)');
ismiss = any(ismissing(A(:,{'Mean_left','Mean_right'})),2);
subplot(2,1,2);
[~, hln(1), hln(2)] = plotyy(A.Sample(~ismiss), A.Mean_left(~ismiss), A.Sample(~ismiss), A.Mean_right(~ismiss));
set(hln, 'marker', 'o');
title('Sample dropped if missing in either dataset');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Test and Measurement에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by