Troubleshooting Matlab Code: Tips and Tricks for Beginners

  • Thread starter eliassiguenza
  • Start date
  • Tags
    Matlab
In summary, the conversation is about someone needing help with using MATLAB and encountering an error in their code. They share their script and a function they created, but are unsure why they are getting an error. They receive a response suggesting they check a link for help with the function they used and a suggestion to put the first two arguments in matrix form. The person asking for help agrees that this is not an advanced physics problem and thanks the responder for their help.
  • #1
eliassiguenza
24
0
Anyone Help Matlab! Please!?

I am pretty bad at using matlab, i have never used it before and i don't know what's wrong with my code, i would honestly appreciate if someone could give me a hand.

Script:
x=linspace(0,5,10)';
y=[2.75 4.83 5.05 6.80 8.83 8.64 11.03 13.20 13.08 15.68]';
sy=[0.5 0.6 0.7 0.8 0.9 0.9 1.0 1.1 1.1 1.2]';
[c,sc]=regress(x,y,sy,1);
plot(x,polyval(c,x),x,y,'o');
errbar(x,y,sy)

Function:

function sc = cerror_2(x,y,sy)
% This function calculates the errors in the fitted coefficients a and b for
% a straight line fitting problem.

A=(sum (x.^2) ./ (sy.^2));

B=(sum (1 ./ sy.^2));

C=(((sum (1./sy.^2) * ((sum (x.^2) ./ (sy.^2))) - (sum (x./sy.^2)))));

sa = (1./C.*A);

sb = (1./C.*B);

sy = [sb,sa];


end

Error

? Error using ==> regress
Too many input arguments.

Error in ==> Problem11_Executer at 4
[c,sc]=regress(x,y,sy,1);
 
Physics news on Phys.org
  • #2


eliassiguenza said:
I am pretty bad at using matlab, i have never used it before and i don't know what's wrong with my code, i would honestly appreciate if someone could give me a hand.

Script:
x=linspace(0,5,10)';
y=[2.75 4.83 5.05 6.80 8.83 8.64 11.03 13.20 13.08 15.68]';
sy=[0.5 0.6 0.7 0.8 0.9 0.9 1.0 1.1 1.1 1.2]';
[c,sc]=regress(x,y,sy,1);
plot(x,polyval(c,x),x,y,'o');
errbar(x,y,sy)

Function:

function sc = cerror_2(x,y,sy)
% This function calculates the errors in the fitted coefficients a and b for
% a straight line fitting problem.

A=(sum (x.^2) ./ (sy.^2));

B=(sum (1 ./ sy.^2));

C=(((sum (1./sy.^2) * ((sum (x.^2) ./ (sy.^2))) - (sum (x./sy.^2)))));

sa = (1./C.*A);

sb = (1./C.*B);

sy = [sb,sa];end

Error

? Error using ==> regress
Too many input arguments.

Error in ==> Problem11_Executer at 4
[c,sc]=regress(x,y,sy,1);

It seems to me MATLAB doesn't like the way you call the function regress. See http://www.mathworks.com/help/toolbox/stats/regress.html". If you need any help just ask but i think you should get the answer by reading the link i gave you! You have to many arguments and i think you want to put the first 2 arguments in a matrix form.

P.S. i don't think this is advanced physics!
 
Last edited by a moderator:

What is Matlab and how is it used?

Matlab is a programming language and numerical computing environment used for scientific and engineering applications. It allows users to analyze, visualize, and manipulate data, as well as create algorithms and models for various tasks.

How do I get started with Matlab?

To get started with Matlab, you can download and install the software on your computer. You can also access it through a web browser with a MathWorks account. Once you have access to Matlab, you can explore its various functions and tools through tutorials and documentation provided by MathWorks.

Can Matlab be used for data analysis?

Yes, Matlab has a variety of built-in functions and tools that make it suitable for data analysis. It can handle large datasets, perform statistical analysis, and create visualizations to help interpret the data. It is commonly used in fields such as finance, engineering, and biology for data analysis purposes.

Are there any online resources for learning Matlab?

Yes, there are many online resources available for learning Matlab, such as tutorials, courses, and forums. MathWorks offers comprehensive documentation and tutorials on their website, and there are also many third-party websites and YouTube channels that provide tutorials and tips for using Matlab.

Can I use Matlab for machine learning and artificial intelligence?

Yes, Matlab has a specific toolbox called the Machine Learning Toolbox that provides a variety of functions and tools for implementing machine learning and artificial intelligence algorithms. It also has a deep learning toolbox for building and training deep neural networks.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
116
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Advanced Physics Homework Help
Replies
2
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
928
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
Back
Top