How to save two variables and create a function to use it later
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Image Analyst
2022-6-25
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!