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)
Show older comments
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
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?
Image Analyst
on 7 Oct 2015
What code did you use? Show your code, including the code that generated the initial matrix.
Answers (1)
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
0 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!