|
On Sep 9, 2:05 pm, "Andre Brito" <andre_brit...@hotmail.com> wrote:
> 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.
>
> (Maybe it has been answered before how it can be done, or that this is not the correct way to do it, or I'm missing something really obvious but I couldn't find a similar problem with the search terms I've used)
>
> 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,
> Andr
you would have to do:
[ab(1) ab(2)] = ind2sub([3 3],5);
By specifying only one output for ind2sub, such as when you type:
ab = ind2sub([3 3],5);
it doesn't care that ab used to be a 2x1 vector. It will override
that and make it a 1x1 vector, since you're telling ind2sub to only
return one variable.
|