How to save two variables and create a function to use it later
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I have the following question, how can I create a function from two variables and then call it, for example I have the time that is a variable 'x' of 1000x1 and another variable of 'y' of the same size, these are data columns . I need to save this data to later call it in a function
0 commentaires
Réponses (1)
Image Analyst
le 25 Juin 2022
Try this to save your two vectors in a .mat file and then recall them later
% Save time and y variable
save('Time Data.mat', 'x', 'y');
% Now recall it. You can have this in a different script or the same script.
s = load('Time Data.mat'); % s is a structure variable.
% Extract the fields into individual vectors.
x = s.x;
y = s.y;
To create a function that will use those two variables:
function someResults = UseXY(x, y)
% Do something with x and y, such as
plot(x, y, 'b-', 'LineWidth', 2);
% Optionally return something.
someResults = true; % Whatever you want.
Now to call the function from a script or other function:
% Define x and y somehow first, then call UseXY:
someResults = UseXY(x, y)
0 commentaires
Voir également
Catégories
En savoir plus sur Language Support dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!