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

The Archive Base Latest Questions

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

In Matlab I’m using oracles data provider to query an oracle database. I want

  • 0

In Matlab I’m using oracles data provider to query an oracle database. I want to fill a matlab matrix or 2D array with the result. I’m a .NET guy but not strong in Matlab. We have analysts who use Matlab but don’t know anything about .NET so we’re sort of stuck. We don’t want to dish out the 2k for the Matlab database toolkit they have so that’s why we’re using .NET to query the database from Matlab.

Any ideas how I can easily convert a datatable from .NET to a matrix or 2D array in matlab? Note that we are using the ODP.NET so the normal ADO.NET GetRows() isn’t there. That’s what I would use if we were using MS’s OLE for oracle but the PC’s are Win 7 64-bit and MS doesn’t support oracle anymore on that platform. You have to use oracles ODP and so that’s what we’re using. Using anything else isn’t an option atm so the solution needs to keep that in mind.

Currently I’m able to query the database, and loop through each row/col but having issues adding to a matrix. Namely because I would need to store both numbers or strings in the matrix and while looping through each column I’m getting the type for conversion but for some reason strcmp() isn’t returning a match even though it looks like it should:

for r = 1:rowCount
    for c = 1:colCount
        type = tbl.Rows.Item(r).Item(c).GetType().ToString();
        val = tbl.Rows.Item(r).Item(c);
        if strcmp(type,'System.Decimal') == 1
            m(r, c) = tbl.Rows.Item(r).Item(c).ToDouble();
        elseif strcmp(type, 'System.String' == 1) || strcmp(type, 'System.DateTime' == 1)
            m(r, c) = tbl.Rows.Item(r).Item(c).ToString();
        end
        m(r, c) = tbl.Rows.Item(r).Item(c).ToString();
    end
end

With this in mind, how can I make a matrix or 2D array accept any type of data? A variant if you will. I was doing m = zeros(rowCount, colCount); but this seems to make it expect numbers, which makes sense, but I still would want to hold both numbers and strings and let the users figure out the columns they wish to do the math on.

  • 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-05T09:07:27+00:00Added an answer on June 5, 2026 at 9:07 am

    This line is problematic:

     strcmp(type, 'System.String' == 1)
    

    Instead of testing that type equals to System.String, it checks whether 'System.String' == 1 is the same string as type.

    I propose to change it to

     isequal(type,'System.String');
    

    Or even better, prefer switch to if-elseif, because it saves you code lines:

      switch type
        case 'System.Decimal'
            m(r, c) = tbl.Rows.Item(r).Item(c).ToDouble();
        case {'System.String', 'System.DateTime')
            m(r, c) = tbl.Rows.Item(r).Item(c).ToString();
        otherwise
            assert(false);
        end
    

    This happens because switch can handle string arguments, and compare them correctly.

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

Sidebar

Related Questions

Using MATLAB , I have an array of values of size 8 rows x
In MATLAB I'm using a couple of java routines I've written to interface with
In MATLAB, how do you write a matrix into an image of EPS format?
Using MATLAB, I have this code: value = input('>> Enter a value: '); and
İn Matlab, I want to threshold a grayscale image to convert it to a
Apparently Matlab load loads the data from a .mat file into the variable that
In Matlab, one can access a column of an array with : : >>
In matlab, I can create a structure array (struct) by doing the following. person.name
In matlab, you can re-use the result of the (non affected) preceding calculous: it
In matlab, is it possible in any way to do the following: By using

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.