[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: searching for the elegant code (matrix indexing and more)
From: |
Markus Appel |
Subject: |
Re: searching for the elegant code (matrix indexing and more) |
Date: |
Thu, 23 Jan 2014 18:26:59 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
On 01/23/2014 01:23 PM, oxy wrote:
> hi guys
>
> look at these: i can generate a matrix with all
> possible combinations.
>
> np=4 % number of parameters. Ex: a, b, c, d
> m=zeros(0);
> for l=1:(np-1)
> m=[m; zeros(np-l,l-1), ones(np-l,1), eye(np-l)];
> endfor
>
> Now just need to change 0 for : (or 1:dim).
> In other words:
>
> 1 1 0 0 -> (1, 1, :, :) for the first row of matrix m.
>
> I'm struggling but dont find a way!
>
> thx for your creative support!
>
> ps: hey markus, i didnt get your point yet ...
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
The code I posted earlier avoids the problem you have, the sig matrix
gets permuted (i.e. the dimensions are rearranged) and then the two
first ones are selected by (:,:,1,1,1). The loops run through all
possible combinations.
If you want to do it your way, have a look at the function subsref. For
example, if you would like to index your matrix sig with the first row
of matrix m by replacing 0 with : , you would do:
idx.type = '()'
idx.subs = cellfun( @(x) ifelse(x==0,":",x), num2cell(m(1,:)),
'UniformOutput', false)
submatrix = squeeze(subsref(sig,idx))
Markus