How to merge two test scripts into one

28 ビュー (過去 30 日間)
Xiaoxuan Guo
Xiaoxuan Guo 2021 年 7 月 1 日
編集済み: Shubham Khatri 2021 年 7 月 5 日
Hi! I have two seperate scripts for different behavioural tests now (.m file). They record and save data to different paths. I want to merge the two tests so they could be ran one after another without having to initialise psychtoolbox twice and with all the data saved into one file in the end. Any idea how to do this in a simple way?
  3 件のコメント
Xiaoxuan Guo
Xiaoxuan Guo 2021 年 7 月 1 日
I think if I do that they'd still run seperately, the only difference is I won't need to change folders...
Mathieu NOE
Mathieu NOE 2021 年 7 月 2 日
hello
why not create a main code that calls your two files once transformed as functions ?

サインインしてコメントする。

回答 (1 件)

Shubham Khatri
Shubham Khatri 2021 年 7 月 5 日
編集済み: Shubham Khatri 2021 年 7 月 5 日
Hello,
To my understanding, you have two functions and you want to call them one after other. You can do it in two different ways.
Create two function files for your two different functions. (Remove all other information except the function declaration part from the file and save the file as your 'function name'.)
I am attaching a code with example
function [Add]=f1(a,b) %function f1 saved as f1.m
Add=a+b;
end
function [mul]=f2(a,b) %function f2 saved as f2.m
mul=a*b;
end
Now you can do two things.
  1. Create a seperate function in a third file which calls the two functions one after other. Lets name this function as f3. Now you can use this function in your working files.
function f3(x,y) %function f3 saved as f3.m
f1(x,y) %calling f1 and f2 one after other
f2(x,y)
end
2. Another approach is, simply calling f1 and f2 in your working file to call and execute in any order you want.
You can also add loop to any of these functions to call each or both functions any number of times you want.
Refer to these (Answer 1 Answer 2) community answers for your support.
Also, refer to these documentation link on creating and caling functions.
Hope it helps

カテゴリ

Help Center および File ExchangeInstallation and Operational Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by