data import from mat file
1 次查看(过去 30 天)
显示 更早的评论
I have a mat file named as xyz.mat, the mat file contains 10 variables named as a_1, a_2, a_3......a_10.
1. I want to develop a script that will load this mat file.
2. Load the variables and record their number 1 to 10 automatically.
3. since there are 10 variable (a_1 to a_10) , a function abc will be run 10 times, one time for each variable , the result after processing of each variable will be stored in varaibles R_1 to R_10. The script should be a generic one it will remain valid for even more than 10 variables.
2 个评论
Geoff Hayes
2020-8-10
jibs - what have you tried so far? Please give us an idea of what you have attempted. Also, strongly consider not using variables that are numbered and use an array (perhaps cell) instead to manage all of the data.
回答(1 个)
hosein Javan
2020-8-10
instead of a_1 ,a_2,..., define a vector "a" where its elements a(1), a(2), ... are your input argument. your function should look like this:
function R = abc(a)
% write your function
end
now for your script:
load('xyz.mat') % load input data a
R = abc(a) % call function abc and calculate R
save('Results.mat','R') % save R to the file Results.mat
8 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!