フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by