필터 지우기
필터 지우기

matlab division help needed

조회 수: 2 (최근 30일)
Susan
Susan 2011년 3월 14일
I need to perform the thinning algorithm and i am stuck in the division part
t = t - exp (u \sin (x));
i programmed this in matlab and i got an error the mldivision because the two sides are not of the same size ! i am aware both should be equal of the same size but in the algorithm i need to do this kind of division and i dont know how to get my way around it in matlab..
this is my code so far
i = 0; t = 0; u = rand (0,1); x = -pi:.1:pi; t = t - exp (u \sin (x));
while t < T u2 = rand (0,1); if u2 <= (sin(x) \ max(sin(x))) u2; end i = i+1;
end

채택된 답변

the cyclist
the cyclist 2011년 3월 14일
It looks like you have a syntax error where you assigned a value to "u".
I'm guessing that you wanted to assign it a random value from 0 to 1, but instead you made a random array of size 0x1 (an empty array).
Instead, try
u = rand(1,1);
which will be a single, random value. Do the same with "u2" inside the loop.
After that, I think you have other errors, because I see no value assigned to T, and even if there were, it looks like your while loop will never change the condition you are checking, so it will loop infinitely. Specifically, your "if" statement inside the loop will not kick you out. You need a "break" command.
  댓글 수: 2
Susan
Susan 2011년 3월 14일
i changed the random variable part and I set T = 100 for the time being but i still got error for the division part..
if u2 <= (sin(x) \ max(sin(x)))
I tried the dot but still not working?!
the cyclist
the cyclist 2011년 3월 15일
You might want to re-post your code, because I'm not really sure what you've done to try to fix it.
Also, are you aware of how to use breakpoints? You can halt the execution of your code on any line, and look at each variable to see if it is doing what you expect.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sisi Ma
Sisi Ma 2011년 3월 14일
maybe you are looking for the "dot division" (in matlab a.\b). it performs element by element division of two maxtrix.
  댓글 수: 1
Susan
Susan 2011년 3월 14일
Thanks for the help, I did it for the first division and i dont have error now but for for the second division I still have error..
if u2 <= (sin(x) \ max(sin(x)))
any idea where I am going wrong ???

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 4월 10일
I'm still uncertain that the \ operator was wanted rather than the / operator ??

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by