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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:24:27+00:00 2026-06-05T17:24:27+00:00

Does anyone know how to store a 1-dimensional Matlab array in a single field

  • 0

Does anyone know how to store a 1-dimensional Matlab array in a single field of a table in Microsoft SQL Server (and how to retrieve it too)? I would like to be able to store an array of Matlab data that isn’t necessarily a fixed size, and I’ve considered storing it as a comma-delimited string, but I am hoping there is a more elegant solution. My thinking is that it should be the same as storing and reading a byte[]. However, I have been trying for hours now and haven’t been able to find anything really helpful on the internet. Here is my Matlab code for storing the array (using ADO):

buf = [1,2,3,4,5]; 
buf = int8(buf);
cmd = actxserver('ADODB.Command');
cmd.ActiveConnection = db.connection; % db.connection stores my connection
% Note that Matlab throws an error when setting the ActiveConnection. This
% command is still valid though and works, so the error should be ignored

cmd.CommandText = 'INSERT INTO dbo.TESTTABLE VALUES(?)'; % According to the MSDN
% website, this should be @val instead of ?, but for some reason that doesn't 
% work and the ? does.

param = cmd.CreateParameter(@val',205,1,8000,buf);
cmd.Parameters.Append(param);
cmd.Execute();

It may be that this code is correct and I just don’t know how to read it back again. Also, I gave an array of size 5 as an example, but I would like to be able to store much larger arrays.
Thanks for your help,

Maddie

  • 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-05T17:24:30+00:00Added an answer on June 5, 2026 at 5:24 pm

    For those of you who are attempting a similar problem, I have found a method that works. The code I posted in my question is correct for storing a byte array from Matlab into a MS SQL Server database. You should know, though, that I am storing it into a field of VARBINARY(MAX) and that it automatically gets stored unsigned. Also, it will only store an array that is like
    buf = [1,2,3,4,5]
    and will only store the first value of and array that is like
    buf = [1;2;3;4;5]

    When you retrieve it, in a ADO recordset for example, you will have to convert it back to int8 which can be done like in Amro’s answer.

    As for the serialization, I wrote a simple Java class that implements Serializable to convert an object to a byte array and vice versa. Since Java can be called from Matlab, this method worked really well, and now I can store and retrieve any Matlab vector, array, or string in a varbinary column.

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

Sidebar

Related Questions

Does anyone know how to store an array in Monotouch NSUserDefaults? One possible method:
Does anyone know a method other than string table to store strings in resource..
Does anyone know how I can store large binary values in Riak?
Does anyone know any public API or a solution to store screenshot images to
Does anyone know how the store template system works in dbdirector? I want to
Does anyone know where/how does NSUserDefaults store the information for persistence? I'm just curious
Does anyone know of a reliable way to store data to use across pages
Does anyone know why native2ascii generates lower-case hex codes, while Properties.store() produces upper-case hex?
Does anyone know how to get the board, like in the picture? https://podio.com/store/pack/110-demo-scrum-board?return_type=&return_id=46 Regards,
Does anyone know if administrators of a magento store receive an email when a

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.