خرید بک لینک

Vote count: 0

For example I have one binary array with size of 9 as b = [0 1 0 1 0 1 1 1 1], Then another array 'm' with size of 7 as m = [21 28 36 45 45 66 66]. Here i want to change all the zeros of 'b' by 1st element of m then replace 1's of b by consecutive elements of 'm' so my output 1D array should be like k = [21 28 21 36 21 45 45 66 66]. Below is my code i really don't know where i did mistake please help me to solve this

b= [0 1 0 1 0 1 1 1 1];
b=b(:);
m = [21 28 36 45 45 66 66];
m = m(:);
k=zeros(size(b));
for i=1:length(b)
    for j=2:length(m)
        if b(i)==0
        k(i)=m(1);
        else
            k(i)=m(j);
        end
    end
end

am getting output as k = [21 66 21 66 21 66 66 66 66]

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 23 فروردين 1395 ساعت: 1:19

صفحه بندی