Tags: easier, globalgt, life, mahulkar, matlab, practice, programming, variables, vishal, wrotegtgt

Don't Understand

On Programmer » Matlab

1,013 words with 0 Comments; publish: Fri, 09 May 2008 23:31:00 GMT; (20078.13, « »)

Vishal Mahulkar wrote:

>

> I know it is not a good programming practice to use global

> variables,

> but it makes my life a lot easier.

> I have a global variable lets say it it named foo

> I define it in a file1.m as:

> function file1()

> global foo;

> foo = [];

> In another file I want to update its value to a structure

> function file2()

> global foo;

> if( true )

> foo = struct('a','a','b','b');

> end

>

> When I do this i get following error:

> ? The following error occurred converting from struct to double:

> Error using ==> double

> Conversion to double from struct is not possible.

> can anyone tell me what this is or how to avoid it?

> Thanks,

> Vishal

>

Vishal,

Try:

foo = setfield (foo, 'a');

foo = setfield (foo, 'b');

hth,

Scott

All Comments

Leave a comment...

  • 0 Comments