I'm somewhat new to Matlab and am having issues with a nested "for" and "if" loop. My code is below. This code is combining a binary signal with a cyclic one. I'm trying to create a matrix with the amplitude condition in the first column and in the second column I want the sum of the number of data points where the binary signal reads "1" and the analog cyclic signal's value is above the amplitude condition. I know the if loop works like I want because when I isolate it it gives me the results I want.(adsbygoogle = window.adsbygoogle || []).push({});

The problem is with the for loop. The second column has all the same number when I know they should vary. Every value is equal to what the correct value is for the first row. After the first row every number is the same for some reason.

n=length(stab(:,1));

prob=zeros(2,2);

prob1=zeros(n,1)

for k=1:100

a(k)=k;

for i=1:n

if ((z2(i)>=a(k))||(z2(i)<=-a(k))) && (stab2(i)==1)

prob1(i)=1;

end

prob(k,2)=sum(prob1);

end

prob(:,1)=a;

end

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# My Matlab for loop wont output the matrix I need

Loading...

Similar Threads for Matlab loop wont |
---|

Binary bitstream from QPSK with MATLAB? |

Python How can I run Python by getting values from Matlab |

What is each step of this Matlab program doing? |

C/++/# Help with MATLAB code? |

Numerical Integration with variable limits MATLAB |

**Physics Forums | Science Articles, Homework Help, Discussion**