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

The Archive Base Latest Questions

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

In Matlab or GNU Octave I’d like to do something like this: x=struct(‘a’,1,’b’,2,’c’,[1 2;3

  • 0

In Matlab or GNU Octave I’d like to do something like this:

x=struct('a',1,'b',2,'c',[1 2;3 4])
y=x(:) % array-ification of a struct
save -ascii y.txt y
z=load('y.txt')
x(:)=z % struct-ification of an array 

I want to serialize/pickle a structure and recreate it later, allowing easy read/save/manipulate in other languages. I’d prefer the intermediate form to be ascii text rather than binary to facilitate human reading/editing/debugging.

Am I forgetting some clever (:)-like slicing for structs or cell arrays?

  • 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-27T04:03:31+00:00Added an answer on May 27, 2026 at 4:03 am

    I think what you want is something like:

    x = struct('a', 1, 'b', 2, 'c', [1 2; 3 4])
    save('y.txt', '-struct', 'x', '-ascii')
    

    But I do not think you can easily recreate it from the resulting file: there is data loss (the fieldnames are lost). If you don’t use the -ascii option, it can be fully recreated using:

    save('y.mat', '-struct', 'x')
    y = load('y.mat')
    isequal(x, y) % returns true
    

    Additionally load can only load a rectangular array of numbers of ASCII text (see http://www.mathworks.com/help/techdoc/ref/save.html and http://www.mathworks.com/help/techdoc/ref/load.html for the limitations). If you wish to keep the fields of the struct in your serialized form, you might look into the “fieldnames” function.

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

Sidebar

Related Questions

In matlab, I can create a structure array (struct) by doing the following. person.name
Does MATLAB have a blackhole or discard variable? Say I'm doing something like: [
In Matlab, I recall being able to declare an array and initialize it and
Using MATLAB, I have this code: value = input('>> Enter a value: '); and
Apparently Matlab load loads the data from a .mat file into the variable that
In matlab I would like to read from a structured, and rather big, file
In Matlab, one can access a column of an array with : : >>
In Matlab, I have a loop that performs operations on arrays. I would like
I'm currently working on writing a version of the MATLAB RegionProps function for GNU
Matlab is displaying a black border around a plot and I would like 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.