Variable unrecognized in function

so i wrote this code and it seems to work fine on its own but everytime I try to run it as a function it keeps showing variable unrecognized. The variable is column vector imported from excel.

답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 2월 21일

0 개 추천

It would appear, based on the error message, that your function does not create a varibale Nu. Make sure you are either passing the variable into your function, or that you create it inside the function.

댓글 수: 2

Tanveer Islam
Tanveer Islam 2022년 2월 21일
Thank you. So it worked after I copied and pasted the vectors from the workspace. So, is there any other efficient way of using large excel sheets of data inside a function. Because I used the import data and that didnt work for the functions or is there something I likely did wrong?
You could import them inside your function, but the more typical way to get data into a function is to pass it in as one of the inputs. See here.
Here's a simple example, but what is passed in could be anything you can capture in a variable.
% scripting
a = 5;
b = a.^2
b = 25
% same calculation, but now performed in a function.
c = myfunc(a)
c = 25
function out = myfunc(in)
out = in.^2;
end

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

질문:

2022년 2월 21일

댓글:

2022년 2월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by