matlab division help needed

6 次查看(过去 30 天)
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