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 7582463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:26:27+00:00 2026-05-30T18:26:27+00:00

I am completely stuck with this: I start out with a flat file type

  • 0

I am completely stuck with this: I start out with a flat file type of list I get from an SQL statement like this and want to transform it into a 4D array.

SELECT a1, a2, a3, a4, v FROM table A;

a1 a2 a3 a4 v
--------------
2 2 3 3 100
2 1 2 2 200
3 3 3 3 300 
...
  • a1 to a4 are some identifiers (integers) from a range of (1:5), which are also the coordinates for the new to be populated 4D array.
  • v is a value (double) e.g. a result from a measurement.

What I now want is to transform this list into a 4D array of dimension (5,5,5,5) where each v is put at the right coordinates.

This could easily be done using a for loop, however as I have lots of data this is not really feasible.

If I had just 1 dimension, I would do somesthing like this:

a1 = [2;5;7];           % Identifiers
v = [17;18;19];         % Values
b1 = (1:10)';           % Range of Identifiers
V = zeros(10,1);        % Create result vector with correct dimensions
idx = ismember(b1, a1); % Do the look up
V(idx) = v;             % Insert

My question: How can I do this for the above mentioned 4D array without using a for loop. Is there a “Matlab Way” of doing it?

Any help is greatly appreciated!

Thanks,
Janosch

  • 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-30T18:26:29+00:00Added an answer on May 30, 2026 at 6:26 pm

    You should be able to do what you want using linear indexing, and the sub2ind function. It would look something like this.

    x=zeros(5,5,5,5); %initialize output vector
    
    i = sub2ind(size(x),a1,a2,a3,a4);
    
    x(i) = v;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I haven't been doing this for long but I'm completely stuck on this.
So, to explain this, I'll start out by going through the application stack. The
I'm completely stuck and need your help... I've created a webservice stub with jaxb
Is it completely against the Java way to create struct like objects? class SomeData1
Let me start by saying I am not an SQL or SQL Server expert
This may be closed, a couple of minutes from now, but I think I
I have a completely blank .aspx file residing on an IIS6 web server. The
If I put the wrong connection URL in my hibernate.cfg.xml file, I want to
Can someone please tell me where these extra characters are coming from? This is
I'd like to use make to get a modular build in combination with continuous

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.