Addition of matrix in a loop
Show older comments
I have four matrix :
r1=[1 2 3 4 5];
r2=[3 4 5 6 7];
d1=2*r1+5
d2=5*r2-2;
I need to add these two matrix such that result matrix
d=d1+d2
for elements in
r1==r2 (for r1=r2=3,4,5)
and for
r1==[1,2], d=d1
and for
r2==[6,7], d=d2.
Result must get matrix should be 1x 7. I could add these a zeros matrix but want using loop which can be extend to any other matrix as well.
NB: Took the liberty to try to clarify a little as I understood the question--dpb
4 Comments
sagar pokhrel
on 30 Dec 2014
dpb
on 30 Dec 2014
It'll work for any set of vectors with the underlying pattern.
sagar pokhrel
on 30 Dec 2014
Edited: dpb
on 31 Dec 2014
dpb
on 31 Dec 2014
Ya' lost me...don't see how the above matches the example's pattern nor quite follow what you're actually trying to do in the latter. Note, however, that intersect may not succeed with floating point comparisons owing to the vagaries of making floating-point tests for equality. The former example works because the vectors are integral values; for floating point for robustness you'll probably need to use a "fuzzy" compare.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!