Identify and delete a specific column?

조회 수: 11 (최근 30일)
Ana Castanheiro
Ana Castanheiro 2016년 9월 29일
편집: Guillaume 2016년 9월 29일
Hi guys!
I need to delete 1 specific column, which may be in different positions (e.g. it can be the 1st, 2nd or 3rd column) depending on the file in use. The specific column to delete is the one where in the 1st row indicates 'O' (O for the element Oxygen). This might be simple, but I'm at beginner level. Any help would be very much appreciated!
  댓글 수: 2
Massimo Zanetti
Massimo Zanetti 2016년 9월 29일
Column of what? What is your data, matrix, cell, array? Put examples in your explanation otherwise no one can understand your problem.
This will help you to get an answer.
Ana Castanheiro
Ana Castanheiro 2016년 9월 29일
Thanks Massimo!
Well I tried to put together the ID of chemical element (1st row in the image) with the composition, but I'm not sure how to distinguish between matrix and cell.
Anyway, the image shows how I have my data. I need to find a way to identify the column with O, and delete this column from the data. And my input source files can have the O in different positions.
I tried to use the find function, but I'm not sure that I can use it for my data. And maybe you can help in this fundamental question: make sense to have data built-up like mine, with both values with "text"? Thanks again!

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

채택된 답변

Guillaume
Guillaume 2016년 9월 29일
편집: Guillaume 2016년 9월 29일
YourCellArray(strcmp(YourCellArray(1, :), 'O'), :) = []
will delete all columns for which the first row is 'O'.
With regards to the data structure, it's fine to have it as you have as a cell array, but maybe better would be to have a table with just numbers and name the columns after the elements:
composition = cell2table(YourCellArray(2:end, :), 'VariableNames', YourCellArray(1, :));
To remove the 'O' column is then trivial:
composition.O = [];

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genomics and Next Generation Sequencing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by