Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
Forcing function ouptut arguments / comma separated list / subsref

Subject: Forcing function ouptut arguments / comma separated list / subsref

From: mohinda

Date: 23 Jun, 2008 13:50:25

Message: 1 of 1

Hi everyone!

I am stuck on the following problem: I would like to create a (class)function returning a variable number of output arguments, which can be used as input arguments for another function.

THe simplest example for this would be a function for indexing a multidimensional array.

For example, let's consider a 3dim array A:

>> A
A(:,:,1) =
     1 1
     1 1
A(:,:,2) =
     2 2
     2 2

I would like to have a function called Indexer(x,y,z) which I could use like this:
and would lead to the same result as using the following syntax:
>> A(1,1,2)
ans =

The problem is that I don't find a way to force the function Indexer to return 3 output arguments. A only takes the first argument returned by Indexer. And thus
>> A(Indexer(1,1,2))
ans =

Of course using this notation yields a correct result:
[x y z]=Indexer(1,1,2);
>> A(x,y,z)
ans =

Now, my approach was to somehow return a comma separated list to be used when indexing A, as this is the only way I now to parse multiple input/output arguments.

>> A(idx1{:})
ans =
>> A(idx2{:})
ans =

My idea was to utilize the subsref method in my own class, where I can manipulate the data as i want to, and then return a variable number of ouput arguments through a comma separeted list.

However, as I started to design the subsref function, I realized a strange thing happening in matlab, and I am realy stuck on this:

As I understand it, using the above notation, i.e. idx1{:}
calls matlab's builtin function subsref(idx1,s), where s is a struct with the following fields:


but when I run the subsref function Matlab returns only the first argument, i.e:
ans =

Wheras when typing directly
ans =
ans =
ans =

I get the correct number of output arguments.

Does anyone know what is happening here. Am I missing something? Any help would be greatly appreciated.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us