Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1113655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:53:24+00:00 2026-05-17T02:53:24+00:00

I’m halfway through figuring out a solution to my question, but I have a

  • 0

I’m halfway through figuring out a solution to my question, but I have a feeling that it won’t be very efficient. I’ve got a 2 dimensional cell structure of variable length arrays that is constructed in a very non-functional way in Matlab that I would like to convert to Clojure. Here is an example of what I’m trying to do:

pre = cell(N,1);
aux = cell(N,1);
for i=1:Ne
  for j=1:D
    for k=1:length(delays{i,j})
        pre{post(i, delays{i, j}(k))}(end+1) = N*(delays{i, j}(k)-1)+i;
        aux{post(i, delays{i, j}(k))}(end+1) = N*(D-1-j)+i; % takes into account delay
    end;
  end;
end;

My current plan for implementation is to use 3 loops where the first is initialized with a vector of N vectors of an empty vector. Each subloop is initialized by the previous loop. I define a separate function that takes the overall vector and the subindices and value and returns the vector with an updated subvector.

There’s got to be a smarter way of doing this than using 3 loop/recurs. Possibly some reduce function that simplifies the syntax by using an accumulator.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:53:25+00:00Added an answer on May 17, 2026 at 2:53 am

    I’m not 100% sure I understand what your code is doing (I don’t know Matlab) but this might be one approach for building a multi-dimensional vector:

    (defn conj-in
      "Based on clojure.core/assoc-in, but with vectors instead of maps."
      [coll [k & ks] v]
      (if ks
        (assoc coll k (conj-in (get coll k []) ks v))
        (assoc coll k v)))
    
    (defn foo []
      (let [w 5, h 4, d 3
            indices (for [i (range w)
                          j (range h)
                          k (range d)]
                      [i j k])]
        (reduce (fn [acc [i j k :as index]]
                  (conj-in acc index
                           ;; do real work here
                           (str i j k)))
                [] indices)))
    
    user> (pprint (foo))
    [[["000" "001" "002"]
      ["010" "011" "012"]
      ["020" "021" "022"]
      ["030" "031" "032"]]
     [["100" "101" "102"]
      ["110" "111" "112"]
      ["120" "121" "122"]
      ["130" "131" "132"]]
     [["200" "201" "202"]
      ["210" "211" "212"]
      ["220" "221" "222"]
      ["230" "231" "232"]]
     [["300" "301" "302"]
      ["310" "311" "312"]
      ["320" "321" "322"]
      ["330" "331" "332"]]
     [["400" "401" "402"]
      ["410" "411" "412"]
      ["420" "421" "422"]
      ["430" "431" "432"]]]
    

    This only works if indices go in the proper order (increasing), because you can’t conj or assoc onto a vector anywhere other than one-past-the-end.

    I also think it would be acceptable to use make-array and build your array via aset. This is why Clojure offers access to Java mutable arrays; some algorithms are much more elegant that way, and sometimes you need them for performance. You can always dump the data into Clojure vectors after you’re done if you want to avoid leaking side-effects.

    (I don’t know which of this or the other version performs better.)

    (defn bar []
      (let [w 5, h 4, d 3
            arr (make-array String w h d)]
        (doseq [i (range w)
                j (range h)
                k (range d)]
          (aset arr i j k (str i j k)))
        (vec (map #(vec (map vec %)) arr))))  ;yikes?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.