- Create a main script that calls the function with two place holder variables say “func(a,b)”.
- Make sure that the three files, “file1.mat”, “file2.mat” and “file3.mat” have the data in them named as variable “a” and “b”.
- Then based on which data you want to use, right click that file, and click load. Then the values of a and b from that file are loaded into workspace.
- Then if you run the main script, the function call “func(a,b)” uses these corresponding values from that particular “.mat” file.
How can I use a preselected file in the Current Folder pane in executing a script?
1 回表示 (過去 30 日間)
古いコメントを表示
I have a script that uses multiple inputs, the first of which is the file name, which I always expect to be in a 'stuff_numbers.mat' format. It will work with just this singular input argument. I work with many file names that are cumborsome to remember, with dates and times and record numbers. It's cumbersome to memorize these, or select the file, highlighting the text with the mouse or using the home and shift+end keys to highlight everything, put in the single quotes, include the extension, etc...
The pipe dream solution would be right-clicking the .mat file I want and selecting my function that runs on that .mat data. The second best solution invovles left-clicking the .mat file, and then using a shortcut button on the ribbon above to say "run this function/script on the pre-highlighted file."
Is this possible?
0 件のコメント
回答 (1 件)
sai charan sampara
2023 年 9 月 29 日
Hello James,
I understand that you are trying to find a method of using different .mat files in the file without having to load the .mat file by name manually every time.
One possible solution is to create a main file/script in which the function is called with place holder variables. Then you can load the data into these variables. Make sure that all the .mat files you want to use have the same format in which the data is stored i.e., the variable names and the order is same throughout all the files. In this case you can simply right click the .mat file and click on load to load all the variables into the workspace. Then running the main script will give you the required output based on the data you loaded.
For example, you have a function “func(x,y)” that adds two numbers and returns it as output. If you want to run this function on the data in the file “file1.mat”, “file2.mat” and “file3.mat” you can do the following:
You can refer to the below documentation to learn more about data import and export in MATLAB.
Thanks,
Charan.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!