Borrar filtros
Borrar filtros

How to make my function accept input file?

26 visualizaciones (últimos 30 días)
hrushikesh kyathari
hrushikesh kyathari el 30 de Jun. de 2019
Comentada: Mary el 7 de Abr. de 2024
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?

Respuestas (2)

Guillaume
Guillaume el 30 de Jun. de 2019
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 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 30 de Jun. de 2019
Editada: KALYAN ACHARJYA el 30 de Jun. de 2019
Well Sir +1
Mary
Mary el 7 de Abr. de 2024
He's obviously trying to learn matlab. The attitude isn't necessary

Iniciar sesión para comentar.


Shahid Iqbal
Shahid Iqbal el 30 de Jun. de 2019
function [edges,nodes,path]=PRM(obstacles)
Function is not linked with obstacles file. Try to create this file again spell should be same.
  1 comentario
Guillaume
Guillaume el 30 de Jun. de 2019
Function is not linked with obstacles file
@Shahid, what does linking a function with a file mean? Your answer makes no sense.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by