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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:37:15+00:00 2026-06-10T00:37:15+00:00

I have some code that I parse and extract some matrices from. Theses matrices

  • 0

I have some code that I parse and extract some matrices from. Theses matrices are associated with certain tags.

What I would like to do is store these matrices with their associated tags for future access. So basically, I want to create a file/structure/array/something that gets updated, but that I can also call matrix operations from if I need to in the same run. Furthermore, the next time I run the program I should be able to call the arrays and tags that I’ve recoded so far. In the end, I want a database of matrices and tags.

Can anyone point me in the right direction to get started?

Some pseudocode would be much appreciated.

  • 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-06-10T00:37:16+00:00Added an answer on June 10, 2026 at 12:37 am

    The type of structure that you now are storing your matrices in (in memory) is relevant.

    For example you could store a bidimensional matrix using a structure such as,

    struct {
        size_t w;
        size_t h;
        double **values;
        size_t n;
        char **tags;
    }
    

    and then write it to disk like,

    fwrite(&(m->w), sizeof(size_t), 1, fp);
    fwrite(&(m->h), sizeof(size_t), 1, fp);
    for (y = 0; y < h; y++)
        fwrite(m->values[y], sizeof(double), m->w, fp);
    fwrite(&(m->n), sizeof(size_t), 1, fp);
    for (y = 0; y < m->n; y++)
    {
        size_t len = strlen(m->tags[y]);
        fwrite(&len, sizeof(size_t), 1, fp);
        fwrite(m->tags[y], sizeof(char), len, fp);
    }
    

    and re-read by replacing fwrites with freads:

    if (1 != fread(&(m->w), sizeof(size_t), 1, fp))
        // ERROR
    if (1 != fread(&(m->h), sizeof(size_t), 1, fp))
        // ERROR
    if (NULL == (m->values = malloc(sizeof(double *) * m->h)))
        // ERROR: OUT OF MEMORY
    for (y = 0; y < h; y++)
    {
        if (NULL == (m->values[y] = malloc(sizeof(double) * m->w)))
            // OOM
        if (m->w != fread(m->values[y], sizeof(double), m->w, fp))
            // File truncated error
    }
    if (1 != fread(&(m->n), sizeof(size_t), 1, fp))
        // Truncated
    for (y = 0; y < m->n; y++)
    {
        size_t len;
        fread(&len, sizeof(size_t), 1, fp);
        if (NULL == (m->tags[y] = malloc(len + 1)))
            // OOM
        if (len != fread(m->tags[y], sizeof(char), len, fp))
            // Truncated
        m->tags[y][len] = 0x0; // C strings must be zero-terminated
    }
    

    …but this covers only bidimensional matrices and requires each matrix to be stored into a file of its own.

    Of course you might complicate the system even further and store a single “database” with a header, a number of matrices inside and so on, then store each matrix one after the other.

    Probably, in the long run, you’d be better off checking whether the FITS standard Claudix suggested allows serializing matrices into strings. If they do, you will be able to store those strings into a real database (PostgreSQL, MySQL, or even SQLite3 so you don’t have to have an independent server). This will also allow you not to rewrite the whole whopper every time a tag gets changed, and have much more maintainable code, at the expense of writing two FITS-wrap functions that convert from a memory object to a SQLited field value and vice versa.

    Direct use of FITS might present problems if FITS format doesn’t allow for variable tags to be associated to matrices and vectors.

    If you can’t adapt FITS to write to string objects, you might still be able to use the code above to write a wrapper from matrix object to string (e.g. by base64-encoding the resulting buffer). Once you have the matrix as a string object, it’s just SQL from there:

    INSERT INTO MatrixTable (matrixId, matrixEncoding) VALUES (...);
    INSERT INTO MatrixTags (matrixId, tagName, tagValue) VALUES (2418, 'Taken', '2012-08-20 at noon');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that looks like this: foreach(var obj in collection) { try
I have some code that creates some span tags and each span has its
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
I have some random HTML layouts that contain important text I would like to
I have some C code that parses a file and generates another file of
I have some code that will change the background color of a specific label
I have some code that is supposed to return an NSString. Instead it is
I have some code that generates Visio masters for me, and some masters have
I have some code that causes the box2d physics simulation to stutter forever after
I have some code that runs a model in a loop. Each iteration of

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.