MATLAB: How to sort this looping

ifloopingsort

anyone can help me to short this looping ? because when I want to change setting it's take to long 🙁
clc; clear;
wmin = 0.4; wmax = 1.2;

Best Answer

Rik is right, logical indexing will make it lot simpler and faster,
wmin = 0.4; wmax = 1.2;
it= 1:1000;
then pre-allocate w,
w = zeros(size(it));
then calculate w based on the value of it,
w(it<=425) = (150 - it(it<=425))./150.*(wmin-wmax)+wmax;
w(it>425&it<=550) = wmax-(wmax-wmin)./150.*(it(it>425&it<=550)-150);
w(it>550&it<=650) = (100-(it(it>550&it<=650)-550))./100.*(wmin-(wmax-0.6))+(wmax-0.6);
and so on! Now you know how to write your remaining equations the same way.