How do I use each value in a vector as its own variable to be tested in relation to another variable in its respective vector?
1 view (last 30 days)
Show older comments
Hello, Im trying to take data values like a=[1,2,3,4] and b=[5,6,7,8] and c=[7,8,9,10] and put them into an equation such as x=a-b/c but only with specific value combinations like (a1,b1,c1) and (a2,b2,c2), not test each number with every possible combination. How do I do this without using a loop?
2 Comments
Answers (1)
James Tursa
on 2 Feb 2018
Edited: James Tursa
on 2 Feb 2018
Use element-wise operators. E.g.,
x = a - b ./ c; % The ./ operator with the dot is element-wise division
There also element-wise multiply .* and element-wise power .^ operators. The + and - operators are already element-wise of course.
2 Comments
Image Analyst
on 4 Feb 2018
This question was accepted, indicating to us that it is solved, and many people will ignore it now. Are you still having a problem?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!