How do I select a specific column by name
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everybody.
I have data divided into column and subcolumn in a csv file. I have a code that gives me the specific subcolumn by selecting the number of the corresponding column in the file. But the subcolumn of interest is not always in the same place, so I have to change the number everytime. Instead the name of the subcolumn is always the same. I was wondering if there is a way to input always the column with the specific given name.
I'm adding here an example file I'm working with and a draft of the script. I'm having trouble adding this function, particularly because the name of the subcolumn of interest is on row number 2, and is not the header for the file.
Here the first part of the script:
%
[filename, path] = uigetfile('*.csv');
doricMat = xlsread([path filename]);
%% normalize traces
trace_470 = doricMat(:,6);
trace_405 = doricMat(:,5);
normalizedTrace = (trace_470-trace_405)./trace_405;
background = doricMat(:,5);
%
In this case I'm chosing to analyze column 6 and 5, but the data of interest is not always on columb 6 and 5. I want to change this so it search for the name of the column (i.e. AIn-3 - Dem (AOut-2)). I know the spaces are a problem, but that I can fix with replacing spaces or illegal formats with something matlab can read. But I don't know how to send that command to the second row and not to the headers.
Thank you for your help.
1 Kommentar
dpb
am 28 Mai 2019
Use readtable and you'll get named variables automagically.
The 'headerlines' optional named property is there for the express purpose of skipping uninteresting header and/or blank lines. detectimportoptions will probably be able to decode the file for you and return an import object.
You can modify names at will via a lookup table or other logic...
Antworten (0)
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!