Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
Ben
Posts:
6
From:
Netherlands
Registered:
2/18/10
|
|
Re: Opening struct in function
Posted:
Feb 26, 2010 7:29 AM
|
|
Thanks, I know, have to learn a lot.
I'll try my best.
The goal of my function is to overwrite a matrix in example.mat. The problem is how can I make from a string a variable. Cause in the input of my function I use the string 'data.direction.A'. I recently discovered eval(...), which makes a variable from a string .
But here comes the problem. I can get the data from the struct. But I can't write it back using eval(data.direction.A), because eval(data.direction.A) = C; does not work at rule 17 in the function below.
Also D=eval(data.direction.A); D=C; doesn't work.
How can I fix this problem? Thanks in advance.
function []=FgrowingDataSet(structname,pos,datainput) % input: % structname: name.mat % pos: Matrix needs to be filled with enough zeros. example: data.direction.A, which is located in name.mat. % datainput: selected array of data % Data will be added if: data is not the same and if data is not zero. % Made by Ben
1. load(structname); 2. C = eval(pos); %makes from string variable 3. i = 1; 4. if C(1,1)==0; 5. C(1,1:length(datainput)) = datainput; 6. else 7. while C(i,1) ~= 0; 8. if C(i,1:length(datainput)) == datainput; 9. break 10. else 11. i=i+1; 12. end 13. end 14. C(i,1:length(datainput)) = datainput; 15. end 16. 17. data.direction.A = C; 18. save(structname, 'data', 'structname'); 19. end
|
|
|
|