How to operate a function on some matrix element which is filtered?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi All, I got a bunch of data measurements in csv file. I want to use mle (maximum likelihood), average and variance on the data. But, I found that not all data was accepted. Many data are wrongs, so I want to exclude some data when using functions. Since the data was in matrix format to MATLAB, before I use the function I want to filter the data. For my experiment, the element value should be less than -45. In my data received, I got some values higher than -45 which is doesn't make sense. This is piece of codes:
filename='Measurement_Range_till3000cm.csv';
M = csvread(filename,1,1);
valueOfMLE = zeros(1,35);
valueOfAvg = zeros(1,35);
for Index=1:size(M,2)
%rssi(Index)=rssi(Index)+1;
%if M(:)<-45
for M(:)<-45;
datamle=mle(M(:,Index));
dataavg=mean(M(:,Index));
valueOfMLE(Index) = datamle(1);
valueOfAvg(Index) = dataavg;
end
end
Answers (1)
valid = find(all(M < -45, 1));
nValid = length(valid);
valueOfMLE = zeros(1, nValid);
valueOfAvg = zeros(1, nValid);
for iValid = 1:length(valid)
Index = valid(iValid);
datamle = mle(M(:, Index));
dataavg = mean(M(:, Index));
valueOfMLE(iValid) = datamle(1);
valueOfAvg(iValid) = dataavg;
end
Or maybe this is easier:
M = csvread(filename, 1, 1);
M = M(:, all(M < -45, 1));
n = size(M, 2);
valueOfMLE = zeros(1, n);
valueOfAvg = zeros(1, n);
... And then your for Index=1:size(M,2) etc.
3 Comments
Albert Sagala
on 15 Nov 2017
Edited: Stephen23
on 15 Nov 2017
Jan
on 15 Nov 2017
What does all(M < -45, 1) reply? If this contains one 1 only, this means that only 1 column matches your need, that all values of a column must be smaller than -45. Or do you want to remove the rows?
I do not understand "I need to iterate on each column, excluded in the mle and mean function". Please explain it again: What should be contained in your output arrays?
Albert Sagala
on 16 Nov 2017
Edited: Albert Sagala
on 16 Nov 2017
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!