I have a matrix with 3 columns. How can I find the differences between column 2 and 3 for each value on column 1 and add the results as a 4th column into the same matrix?

3 views (last 30 days)
I have a matrix with 3 columns. How can I find the differences between column 2 and 3 for each value on column 1 and add the results as a 4th column into the same matrix?
  4 Comments
Walter Roberson
Walter Roberson on 7 Oct 2015
What is the data type of your array? It sounds like it might be char() . If it is, then how do you define the "difference" between two characters?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 6 Oct 2015
Not sure what you're asking but I'm taking a guess that you want the differences on a row-by-row basis rather than what you said. So would this work?
m = [m, m(:,3)-m(:,2)]; % Append (col3-col2) onto original m

Categories

Find more on Structures in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!