필터 지우기
필터 지우기

How to make my function accept input file?

조회 수: 26 (최근 30일)
hrushikesh kyathari
hrushikesh kyathari 2019년 6월 30일
댓글: Mary 2024년 4월 7일
function [edges,nodes,path]=PRM(obstacles)
This is my function.I have a csv file named obstacles.But when I run it, I get the message as Undefined variable "obstacles" or class "obstacles.csv".
What should be done?

답변 (2개)

Guillaume
Guillaume 2019년 6월 30일
What should be done?
I'm afraid the answer is: learn matlab. Function inputs are variables. Matlab is not going to magically guess that a particular variable should suddenly get its content from a file that has (parts) of its name identical to a variable name.
Now, you could create your function where the input variable contains the name of the file to load:
function [edges, nodes, path] = PRM(obstaclefilename)
which you script could call with:
folder = 'C:\somewhere\somefolder';
filename = 'obstacle.csv';
[edges, nodes, path] = PRM(fullfile(folder, filename));
The body of the function could start with:
function [edges, nodes, path] = PRM(obstaclefilename)
filecontent = readtable(obstaclefilename); %use readtable or some other file import function
%... rest of the code that uses filecontent
end
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 30일
편집: KALYAN ACHARJYA 2019년 6월 30일
Well Sir +1
Mary
Mary 2024년 4월 7일
He's obviously trying to learn matlab. The attitude isn't necessary

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


Shahid Iqbal
Shahid Iqbal 2019년 6월 30일
function [edges,nodes,path]=PRM(obstacles)
Function is not linked with obstacles file. Try to create this file again spell should be same.
  댓글 수: 1
Guillaume
Guillaume 2019년 6월 30일
Function is not linked with obstacles file
@Shahid, what does linking a function with a file mean? Your answer makes no sense.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by