Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: [ab(1) ab(2) ... ab(N)] ~= [ab(1:N)] ???
Date: Thu, 10 Sep 2009 08:38:03 +0000 (UTC)
Organization: Universit&#228;t  Bremen
Lines: 23
Message-ID: <h8adtb$r4u$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1252571883 27806 172.30.248.37 (10 Sep 2009 08:38:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 10 Sep 2009 08:38:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1426778
Xref: news.mathworks.com comp.soft-sys.matlab:569465


Hi,
basically, what I'm trying to do is to get the output of ind2sub (or of any function, for that matter) to output a vector and assign it to an existing vector. I know I could assign each element of the output to each element of the existing vector. The problem is when the dimensions of the output are not fixed.

What I want to do is to be able to specify an output without MATLAB overwriting it and checking its dimensions. My idea is for this function to work regardless of the dimensions, such as replacing:
[ab(1) ab(2) ... ab(N)] = function(...)
with
[ab(1:N)] = function(...)

As an example, could someone just explain me what is the mechanism behind MATLAB that makes, for example, the function ind2sub output the following:

>> [a b] = ind2sub([3 3],5)
a = 2
b = 2

but if
>> ab = [0 0];
>> ab = ind2sub([3 3],5)
ab = 5

Meaning that it does not detect that the output vector has dimensions different than 1x1.

Cheers,
Andre