Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Opening struct in function
Replies: 3   Last Post: Feb 26, 2010 10:12 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 6
From: Netherlands
Registered: 2/18/10
Re: Opening struct in function
Posted: Feb 26, 2010 7:29 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
17. data.direction.A = C;
18. save(structname, 'data', 'structname');
19. end

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2016. All Rights Reserved.