Can you please help em with this error

Hi, our teacher wants us to write a user defined function that finds the transpse of a matrix, I am new to matlab so i dont exactly know how. This is what i tried clear all; function At = transp (A,n,m) for i=1:m for j=1:n At(i,j)=A(j,i); At end end A = [2 1 4 -2 -3 4 2 -1 3 5 -2 1] At = transp (A,3,4)
but when i run the program i keep geting this error
??? function At = transp (A,n,m)
|
Error: Function definitions are not permitted in this context.
and i dont know how to fix it, if you can help ill be very gratefull thanks :)

Answers (1)

You need to save your function definition in a separate file called transp.m and then call it in a script. You can not put the script and function together.
Type doc, look at the documentation MATLAB->Getting Started->Programming->Scripts and Functions

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 16 Sep 2011

Community Treasure Hunt

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

Start Hunting!