How do I select a specific column by name

조회 수: 9 (최근 30일)
Stefano Cataldi
Stefano Cataldi 2019년 5월 28일
댓글: dpb 2019년 5월 28일
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
dpb
dpb 2019년 5월 28일
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...

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by