Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have made a matlab function, but when I use this function in a program, it is not giving all the outputs (xc,yc,R). Rather it is giving only xc!

This is a function which fits a semicircle on a set of data points. I have a file A having two columns (X and Y). I take x=A(:1) and y=A(:,2). Then using the following function on a program, I suppose to get xc, yc and R. But unfortunately, I am getting only xc!

function [xc,yc,R] = semicircle( x,y )
%To Fit a semicircle on a distribution
%   Detailed explanation goes here

a=[x y ones(size(x),1)]\[-(x.^2+y.^2)]; %vector of parameter

xc = -a(1)/2; 

yc = -a(2)/2;

 R  =  sqrt(a(1)^2/4+a(2)^2/4-a(3));

  % display original data
   figure,plot(x,y,'o'); %original data


   theta=linspace(0,-pi,1000); %generate 1000 angle points, you can change the range of angle

 xx=xc+R*cos(theta);

yy=yc+R*sin(theta);

 hold on;

 plot(xx,yy,'r')

end
share|improve this question
    
this question should be asked in StackOverflow, not here...that's my personal thought –  bryansis2010 Feb 7 '13 at 9:35
add comment

closed as off-topic by Shobhit, Dennis Gulko, azimut, Norbert, Daniel Rust Oct 29 '13 at 18:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is not about mathematics, within the scope defined in the help center." – Shobhit, Dennis Gulko, azimut, Norbert, Daniel Rust
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 4 down vote accepted

This is probably caused by you not calling the function with multiple output arguements. When you want to use the function make sure to call it like so (just like you defined it):

[xc,yc,R] = semicircle( x,y ) 

If you just call

semicircle( x,y ) 

Matlab by default just gives the first output argument.

share|improve this answer
    
YES!!!! Thank you very much... i am just a beginner in Matlab!. good to notice this point. –  aneps Feb 7 '13 at 9:28
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.