How can I combine values from different columns of a matrix into one single column?

13 views (last 30 days)
Kemal on 8 Mar 2013
I have a matrix with three columns and many rows. The first column is the count. There are values in some sections of the second and third columns that I am not interested in. However, they do not overlap. There is no single row for which I want to extract values of both columns. I want to combine the values I am interested in in one single column, either a new column or in one of those two columns.Initially, I assigned NaN to those cells that I am not interested and then I was trying to use a loop but I am new to Matlab so it does not work. Any help will be very much appreciated. Trying to this manually in Excel takes a long time! Thanks!

Accepted Answer

Leah on 8 Mar 2013
it would be helpful to see you code so far, but i think this is what you need. A is your original matrix (nx3)
Anew(index1,1)= A(index1,3)
you could do this quickly in Excel by using an "if" statement

More Answers (2)

Matt J
Matt J on 8 Mar 2013
Index the rows of column 3 that you want and then do a vectorized assignment. If A is your matrix and keeprows are the rows of column 3 that you want to keep,

Sign in to comment.

Azzi Abdelmalek
Azzi Abdelmalek on 8 Mar 2013
Edited: Azzi Abdelmalek on 8 Mar 2013
A=[1 4 6;2 nan 14;3 25 nan;4 78 77]

Community Treasure Hunt

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

Start Hunting!

Translated by