Import CSV files, find extraction condition, and local maxima

Hi everyone,
I am trying to read in multiple .csv files with lot of data (mostly numbers except : the first row contains 2 strings and several numbers, and these first row numbers are actully the same in every .csv)
After that I have to find in the first row the value '50' and get its column and then find the local maxima in that.
Can you pls help me, how to solve this?
Thanks in advance.

4 comentarios

dpb
dpb el 18 de Jun. de 2020
Can you please help us help by attaching a data file so folks have something to work with? :)
It'll probably be a "piece o' cake" but would be much simpler to be able to see what have to work with...
GH
GH el 18 de Jun. de 2020
Hey there,
I created a Google drive link, with a dataset (I have 6 of this kind in one folder) and I also made an .xlsx file, where I highlighted which data - column and rows would like to extract (to find the local maximas in those colums...)and I highlighted the two strings in the begining.
https://drive.google.com/drive/folders/1RU7sAqIykvlhtj-FpdNLhYZchq1_xhGi?usp=sharing
I would appreciate any help.
Thank you very very much, if something is still unclear do not hesitate to comment on it.
Not going there. Why didn't you attach it with the paper clip icon?
GH
GH el 18 de Jun. de 2020
Although, I changed a little on the dataset, I didn't want to leave it on public forever, and I wasn't sure about I can delete the comment later on, but I attached them here now, sorry about that...!

Iniciar sesión para comentar.

 Respuesta aceptada

Grace:
This should do it:
% Create sample matrix.
m = randi(500, 100, 30);
% Find out all the rows that have a 50 in them.
rowsWith50 = find(any(m == 50, 2))
% If any row(s) do, then find the column with the 50 in it,
% and get the max of that column.
if ~isempty(rowsWith50)
firstRowWith50 = m(rowsWith50(1), :);
% Get its column
columnWith50 = find(firstRowWith50 == 50, 1, 'first')
% Find the max of this column over all rows
theMax = max(m(:, columnWith50))
end

4 comentarios

GH
GH el 18 de Jun. de 2020
Thank you very much, yes, it works!
Do you have any idea, how could I read in this type of csv in a cell, where there's the first two data in the first line are strings so the 'csvread' can't work on it...
(Sorry about the google-drive-link idea again, I didn't think it through)
Try importdata(). Or look in csvread() or dlmread(). One or both of them let you specify what row to start with -- how many headerlines to skip.
GH
GH el 19 de Jun. de 2020
Editada: GH el 19 de Jun. de 2020
Unfortunately, it seems like this solution isn't working for me, because 50 would be one of the variable like 'y' and I would like to search in its column the belonging 'x' which is /are the local maximas. Your solution works great for if the value 50 can be also one of the solution. (My x datas are much more smaller values, then 50 so now the code finds 50 as highest in the column, my apologies if I was unclear)
But I managed to read in the csv files due to your tips thank you
Image Analyst
Image Analyst el 19 de Jun. de 2020
Editada: Image Analyst el 19 de Jun. de 2020
This seems to work fine to read in the matrix
data = readmatrix('dataset.csv', 'numHeaderLines', 1)
fprintf('Done running %s.m ...\n', mfilename);

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

GH
el 18 de Jun. de 2020

Editada:

el 19 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by