How to set a lower data limit and then use data from multiple CSV files

1 view (last 30 days)
I have csv files from an imaging technique, where each file is the scalars of a plane along the y-axis. At the extreme ends of the y-axis (top and bottom), there are not enough pixels to accurately represent the image.
What I am trying to do is set a lower limit for the amount of pixels, and then use only the files that meet the criteria. I have seen a few ways to set the limits on the data (see below), but I am not quite sure how to use the data after the limits are set.
function y=bound(p,bl,bu)
    y=min(max(x,bl),bu);
end
Using this method, I can't put anything after the function.
x = (p >= bl) & (p <= bu);
After this, I'm not sure how to go about using the data from only those limits.
Here is my code to cycle through the files and get the pixel number from the csv files. PS is the standard deviation of the number of pixels and PA is the average number of pixels for all the files combined. bl and bu are the upper and lower limits.
csvFiles=dir(fullfile(folder,'*.csv'));
[~,reindex]=sort(str2double (regexp({csvFiles.name}, '\d+','match','once')))
N=csvFiles(reindex);
numfiles=length(N);
for k=1:numfiles
M=csvread(fullfile(folder, N(k).name), 1, 0);
p(k)=length(M(:,2));
end
PS=std(p)
PA=mean(p)
bl=PA-PS
bu=PA+PS

Accepted Answer

Brittany Hallmark-Haack
Brittany Hallmark-Haack on 10 Jul 2020
I found a solution. First I ran a Matlab code to extract all of the desired variables to one csvfile (using forloop as shown in the original question), then I ran the following code on that file to extract only the data I needed.
I extracted the necessary columns based on the data from a single row of the csvfile.
A=csvread('file.csv');
p=A(6,:);
PS=std(p)
PA=mean(p)
bl=PA-PS
bu=PA+PS
x = (A(6,:) >= bl) & (A(6,:) <= bu);
extracted_columns = A(:,x);

More Answers (0)

Categories

Find more on MATLAB Report Generator in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!