|
From: | Bård Skaflestad |
Subject: | RE: a difficult homework |
Date: | Thu, 22 Aug 2019 15:38:42 +0000 |
Alternatively, you could use ACCUMARRAY (with subscripts created by REPELEM) to apply MIN to groups of values extracted from 'c'. The only slightly non-trivial bit is generating the
indices into 'c', but there are very standard CUMSUM-based ways of doing so. Regards, Bård Skaflestad SINTEF Digital, Mathematics & Cybernetics Computational Geosciences group From: Help-octave <help-octave-bounces+bard.skaflestad=address@hidden>
On Behalf Of Nicholas Jankowski On Thu, Aug 22, 2019 at 8:55 AM mmuetzel <address@hidden> wrote:
I have a working solution, but is this a homework assignment? I'm hesitant to just post the full code. The solution is almost always to spread the looped operation over an expanded array (here it can be kept to two dimensions. I've frequently made use of n-dimensional operations, and broadcast projection for this. for large data sets you
have to be careful, as you're trading time for memory) you're working with you c matrix as a single column of data, and looping 4 times, once over each a (and b, but they're looped together, so it's only one extra dimension). you can make four parallel copies of the c matrix, and then apply
the min function. a common way to do quick array duplication is: c = c(:); cc = c .* ones(1,4); or more generally cc = c.* ones(1,numel(a)); then, you notice that min and max functions apply only in one dimension. so min(cc) will give you the min of each column. the tricky part is that you aren't taking the min of the full column, just a portion of it. so you'll need to figure out how to sample only a portion of each column, as specified in a and b, maybe using logical indexing, and take the min
over that. this is complicated by it being a different length portion each time. |
[Prev in Thread] | Current Thread | [Next in Thread] |