extracting a particular element from a matrix
Show older comments
Hi all,
I have a column matrix A (with some common elements in it) and another column matrix B, I have added both the matrices (let the final matrix formed is C). Now I want to extract that element from C, which is formed by the max. value among common elements in A and its corresponding element in B
Suppose
A=[1
2
5
5
10
10
10]
B=[1
3
4
5
7
1
6]
Please help to have my answer as 17 from (5th element of A + 5th element of B
Here both A & B are user defined thus the size and index values may differ
6 Comments
madhan ravi
on 22 Feb 2019
why not just:
[Value,Index]=max(A+B)
TADA
on 22 Feb 2019
I Didn't Understand Exactly What you want.
Are You Trying To Find The Maximal Value Of C, I.E 17, Or The Maximal Value For Each Group Of Numbers In A, I.E [2; 5; 10; 17] Corresponding To The Number In A: [1; 2; 5; 10]
What Have You Tried So Far?
Also I Have To Ask, Is The Next Number In A 17?
Jan
on 22 Feb 2019
@madhan: I assume your code is the solution. Please post it as answer.
madhan ravi
on 22 Feb 2019
@Jan: Done :-)
SATYA BHATT
on 23 Feb 2019
madhan ravi
on 23 Feb 2019
Edited: madhan ravi
on 23 Feb 2019
You say max but why do you say a(12) & a(13) , completely vague and unclear. See if maxk() does your job.
Answers (2)
madhan ravi
on 22 Feb 2019
[Value,Index]=max(A+B)
Jan
on 25 Feb 2019
A bold guess:
index = (A == max(A));
A(index) + B(index)
Categories
Find more on Matrix Indexing 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!