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 :)
回答(1 个)
Fangjun Jiang
2011-9-16
0 个投票
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
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!