简体   繁体   中英

How to create a function that takes a matrix as an input?

I am new to MatLab.

Write a function that takes as input a matrix D ∈ R^(N×2), D_i = (x_i,y_i), and the period ω and returns a plot showing a fit of the data without noise.

I need help with creating the function that takes the input as a matrix and period ω. Here is what I have so far. Am I on the right track?

function F = fftfuntion(D, omega)
check = 0;
x = D(:,1);
y = D(;,2);

You are on track but there are 3 problems:

First: you are using p variable inside your function which is not defined there. If it is defined in your main code you have to insert it to this function by adding an input to your function as p and when the function is called you have to put p there. Your other solution is to set p as a global variable which is not recommended.

function F = fftfuntion(D, omega,p)

Second: you have said that you need omega as an input and you are changing it with omega = 2*pi which is not right.

Finally I don't see any output which I think that's because you are not still done with the function.

Good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM