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)
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
Ashley Nelson
Ashley Nelson on 4 Feb 2018
if I were to do a=[1,2,3,4....1000] and b=[1,2,3] and c=[4,5,6] how can i put them in as values of (b1, c1)(b2, c2) and test that through for every value within a? ex. (a*5)+(a*(BVALUE))/(CVALUE)

Sign in to comment.

Answers (1)

James Tursa
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
Ashley Nelson
Ashley Nelson on 4 Feb 2018
right, but if I were to do a=[1,2,3,4....1000] and b=[1,2,3] and c=[4,5,6] how can i put them in as values of (b1, c1)(b2, c2) and test that through for every value within a? ex. (a*5)+(a*(BVALUE))/(CVALUE)
Image Analyst
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?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!