Writing a function with variable outputs to convert a 3d matrix to 2d

Hello, so I'm very new to Matlab so my apologies if this is a very simple question. I have a 3d matrix for example sized 40x2x4. I want to be able to split this into multiple 2d matrices, so for example a = (:,1,1), b = (:,1,2), c = (:,2,1), d = (:,2,2) etc. However, the dimensions are often variable, so I'm unsure of how to create a function that will create a variable number of outputs depending on the dimensions of the input matrix. I've found varargout, but I'm unsure of if this is what I need and if it is, I'm not sure of how exactly to use it. Thanks for any help here, I really appreciate it! -Jesse

Answers (2)

No. Your inner-conscience is actually telling you that you don't want to do that!
doc mat2cell %is probably closer what you want
Welcome to MATLAB and Answers
See blockproc() or blkproc() or mat2cell() for the splitting and processing. (You often do not need to explicitly split the matrix.)
You do not want to create a variable number of outputs for this situation, as writing an assignment statement that has a variable number of left-hand sides is an advanced MATLAB technique.

Categories

Asked:

on 8 Mar 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!