How do I put a .mat file into a function?
31 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
rose mal
am 27 Feb. 2021
Bearbeitet: Cris LaPierre
am 27 Feb. 2021
I have the following code:
userInput=input("Please choose between the following numbers: 1,2 or 3.");
function Tester(bridges.mat,userInput)
end
I tried having doing the following:
userInput=input("Please choose between the following numbers: 1,2 or 3.");
function Tester(bridges,userInput)
bridges=load(bridges.mat);
end
but it still did not load the data. What am i doing wrong?
0 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 27 Feb. 2021
Bearbeitet: Cris LaPierre
am 27 Feb. 2021
If you know the name of the mat file, you don't have to pass it in. As long as it is accessible (in the current folder, or in a folder that has been added to the MATLAB path), it can load it.
userInput=input("Please choose between the following numbers: 1,2 or 3.");
function Tester(userInput)
bridges=load(bridges.mat);
end
Otherwise, you can look into how to pass inputs to a function. You declare the inputs using varibles, then call the function with the actual values. For example
userInput=input("Please choose between the following numbers: 1,2 or 3.");
% call function and pass in fileName as character array
Tester('bridges.mat')
% function declaration containg variable names
function Tester(fileName,userInput)
% Inside a function, you use the variable names used in the declaration
bridges=load(fileName);
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!