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
참고 항목
카테고리
Help Center 및 File Exchange에서 Language Support에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!