data import from mat file

조회 수: 1 (최근 30일)
jibs
jibs 2020년 8월 10일
댓글: hosein Javan 2020년 8월 11일
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
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.
jibs
jibs 2020년 8월 11일
Actually I'm using a simple gui, having single push button (Load_mat File). By pressing it a mat file is loaded.
The mat file has now 10 variables i.e (a_1 to a_10). It could have more than 10 variables as well. I want all of them to be loaded one by one progamitically after that a function y = abc , will be executed on all variables a_1 to a_10 and their result will be saved in variables R_1 to R_10.

댓글을 달려면 로그인하십시오.

답변 (1개)

hosein Javan
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
jibs
jibs 2020년 8월 11일
k = who('-file','As.mat','a*');
r=zeros(1,length(k));
% % just added these two lines and done it
hosein Javan
hosein Javan 2020년 8월 11일
correct.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by