matlab division help needed

5 Ansichten (letzte 30 Tage)
Susan
Susan am 14 Mär. 2011
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

Akzeptierte Antwort

the cyclist
the cyclist am 14 Mär. 2011
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 Kommentare
Susan
Susan am 14 Mär. 2011
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 am 15 Mär. 2011
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Sisi Ma
Sisi Ma am 14 Mär. 2011
maybe you are looking for the "dot division" (in matlab a.\b). it performs element by element division of two maxtrix.
  1 Kommentar
Susan
Susan am 14 Mär. 2011
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 ???

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 10 Apr. 2011
I'm still uncertain that the \ operator was wanted rather than the / operator ??

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by