Hi,
I have:
solveload=[0 0 0 'x' 'y' 'z'];
And need to determine only the position of the x, the y, and the z, when they could be anywhere in the vector, with 0's elsewhere. I'm finding I need a bunch of if-then's. It must be easier?
Thanks in advance :)
Dave

 Accepted Answer

Star Strider
Star Strider on 18 Jun 2016

0 votes

There seem to be missing information.
What characterises ‘x’, ‘y’, and ‘z’?
What makes them so difficult to find? Range? Real/Complex? Something else?

7 Comments

To find their positions, I need 6 if-then's for "x", 6 for 'y', and 6 for 'z'. Just seems excessive...
How are they organised in the vector?
How can you determine which is which?
They can be arranged any way. x 0 0 y z 0 for example.
This didn't work because when it found the x, it just stopped:
if solveload(1) == 'x'
x(k) = zz(1)*LRF;
elseif solveload(1) == 'y'
y(k) = zz(1)*LRF;
elseif solveload(1) == 'z'
z(k) = zz(1)*LRF;
elseif solveload(2) == 'x'
x(k) = zz(2)*LRF;
elseif solveload(2) == 'y'
y(k) = zz(2)*LRF;
elseif solveload(2) == 'z'
z(k) = zz(2)*LRF;
elseif solveload(3) == 'x'
x(k) = zz(3)*LRF;
elseif solveload(3) == 'y'
y(k) = zz(3)*LRF;
elseif solveload(3) == 'z'
z(k) = zz(3)*LRF;
elseif solveload(4) == 'x'
x(k) = zz(4)*LRF;
elseif solveload(4) == 'y'
y(k) = zz(4)*LRF;
elseif solveload(4) == 'z'
z(k) = zz(4)*LRF;
elseif solveload(5) == 'x'
x(k) = zz(5)*LRF;
elseif solveload(5) == 'y'
y(k) = zz(5)*LRF;
elseif solveload(5) == 'z'
z(k) = zz(5)*LRF;
elseif solveload(6) == 'x'
x(k) = zz(6)*LRF;
elseif solveload(6) == 'y'
y(k) = zz(6)*LRF;
else
z(k) = zz(6)*LRF;
end
I'll need to if-then from 1-6, once each for x, y, and z for this to work.
Do they always occur in ‘(x,y,z)’ order, and are zero elsewhere?
any order of x and y and z, with 0's everywhere else.
0 z x 0 0 y is possible.
Maybe there's a match function, or index, or split....
I’m glad you solved it, because I have no idea how to differentiate x, y, and z from your description.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming 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!