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

  • Home
  • SEARCH
  • 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 6025773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:20:57+00:00 2026-05-23T04:20:57+00:00

I have a 4-dimensional dictionary I made with a Python script for a data

  • 0

I have a 4-dimensional dictionary I made with a Python script for a data mining project I’m working on, and I want to read the data into Matlab to do some statistical tests on the data.

To read a 2-dimensional matrix is trivial. I figured that since my first dimension is only 4-deep, I could just write each slice of it out to a separate file (4 files total) with each file having many 2-dimensional slices, looking something like this:

2 3 6
4 5 8

6 7 3
1 4 3

6 6 7
8 9 0

This however does not work, and matlab reads it as a single continuous 6 x 3 matrix. I even took a look a dlmread but could not figure out how to get it do what I wanted. How do I format this so I can put 3 (or preferably more) dimensions in a single file?

  • 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-23T04:20:58+00:00Added an answer on May 23, 2026 at 4:20 am

    A simple solution is to create a file with two lines only: the first line contains the target array size, the second line contains all your data. Then, all you need to do is reshape the data.

    Say your file is

    3 2 3
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
    

    You do the following to read the array into the variable data

    fid = fopen('myFile'); %# open the file (don't forget the extension)
    arraySize = str2num(fgetl(fid)); %# read the first line, convert to numbers
    data = str2num(fgetl(fid)); %# read the second line
    data = reshape(data,arraySize); %# reshape the data
    fclose(fid); %# close the file
    

    Have a look at data to see how Matlab orders elements in multidimensional arrays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two dimensional array that I need to load data into. I
I have a one dimensional vector of data in R and I want to
I have a 2-dimensional array of objects and I basically want to databind each
I have a two-dimensional array (of Strings) which make up my data table (of
I have a three-dimensional array that I want to reset to zero. It seems
I have an 2 dimensional array. I write 3 values into the array during
I have n=10000 10-dimensional vectors. For every vector v1 I want to know the
I have what amounts to a multi-dimensional array. int[][][] MyValues; What I want is
I have a class that performs some operations on a set of data. The
I have two dimensional float array as below {0.2,0.0,0.3,0.0,0.0} {0.4,0.1,0.0,0.0,0.9} {0.0,0.0,0.0,0.3,0.6} I want to

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.