Versatile Data Structure in MatLab

ezgigurkan
ezgigurkan used Ask the Experts™
on
I need to plot multiple lines on an axis continuously, as in several lines might be drawn on an axis every time I push a button (I have my own simple GUI). The lines are not removed so lines are drawn on top of each other. The problem is that I need to keep certain variables associated with these lines, e.g.

- the handler (so that I can delete the line later on)
- 4-5 numbers
- 2 strings
- 3 vectors of various sizes (and the size of each vector might be different for different lines)

I'll have a button that should iterate through all the lines on the axis, access these variables associated with them and do calculations/delete lines/plot new ones. So I think I need an array of something but I don't know MatLab well enough. If that was Java I'd probably have to use a class, just to keep all these variables in one place.

If anyone knows about a good tutorial that'd be great. Or, if there aren't any such data structures in MatLab, what can I do to achieve what I'm trying to do?

Just to make it more clear, these lines represent Support Vector Machines (Regression). I need the variables for prediction when new data arrive. I'll be assessing different kernels and settings simultaneously.

Appreciate any help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You can create a class in matlab similar to Java/C++ but you would need to create a separate file and in my experience they are usually more trouble than they are worth.

Matlab has a data structure called a cell array that can hold elements of different types.  This would probably be the simplest solution to your problem.

http://blogs.mathworks.com/loren/2006/06/21/cell-arrays-and-their-contents/
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
That's brilliant guys, thanks a lot. I might use both cells and structs. One thing though, how are handlers treated? Can I keep them in cells or structs? And is "handler" a type on its own or a special kind of string or something like that? Once I store it in a cell, can I dereference it without any hassle?
Commented:
Handle is a special variable in Matlab. It returned by certain functions, usually graphical, and points to objects. It has class double (check by CLASS function), but also can be identified as handle with ISHANDLE function. Of course you can store them in cell of structure array.

Author

Commented:
Cheers guys...

Commented:
You can put handles in both cells and structs.  In the following I create a function handle, put it in a struct, then put both in a cell array.
>> a = @(x) 5*x;
>> a(5)
 
ans =
 
    25
 
>> b = struct('x5', a, 'num', 10)
 
b = 
 
     x5: @(x)5*x
    num: 10
 
>> b.x5(b.num)
 
ans =
 
    50
 
>> c = {a,b};
 
>> c{1}(c{2}.x5(c{2}.num))
 
ans =
 
   250

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial