How to perform operations depending on a value in an array
Show older comments
Good day,
Hopefully you can help me with a question, I have a data array, with 18 specific data. I want to make certain operations based on the value in the array. What I don't know is how to write the conditions, I know I need an if and the operator "or" which is "||", I have used it but it doesn't do what I want, so I think I'm misusing the idea.
What I want to achieve is that if the value I have in array C, in the order in which it, is equal to 5, 6 or 7, the data variable is divided by 188, if the value is 8,9,10,11 , 12,13,14,15,16 or 17 the variable data is divided by 396 and if the value is greater than or equal to 18, then it is divided by 1659.5; and the result of the operation is stored in a new array called N for each value. But I have an error because the "or" operator is not used correctly and how to ensure that operations can be performed depending on the value.
I hope you can help me, thanks in advance.
This is the code I have:
C=[10 8 34 7 7 24 11 15 10 13 13 20 17 39 6 9 5 21];
data=2200;
for i=1:length(C)
if C(i)==5||6||7
N(i)=data/188;
elseif C(i)==8||9||10||11||12||13||14||15||16||17
N(i)=data/396;
else C(i)<=18
N(i)=data/1659.5;
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!