0

Getting started with Matlab and mySQL, as a result for my query I get this type of array:

my_result =

  5×1 cell array

    {'a'}
    {'b'}
    {'c'}
    {'d'}
    {'e'}

I'd like to get a simple array like this:

[a, b, c, d, e]

Here's my code:

mysql( 'open', 'my_database', 'usr','passw' )

query = fileread('query1.sql');           
query = sprintf(query)

my_result = mysql(query);

And my attempts at getting a simple array:

my_array = []
for i=1:length(my_result)
   my_array = [my_array, my_result{i}];
end


>> my_array

my_array =

    'abcde'

>> cell2mat(my_result)
Error using cat
Dimensions of arrays being concatenated are not consistent.

Error in cell2mat (line 83)
            m{n} = cat(1,c{:,n});
 

Is there a way to either get the correct format in the first place, or easily convert it properly? Thank you

1
  • MySQL doesn't support arrays, so your question is rather unclear. Commented Mar 5, 2021 at 23:23

1 Answer 1

2

just use the cell2mat built-in function

a{1} =  'a' 
a{2} =  'b' 
a{3} =  'c' 
a{4} =  'd' 
a{5} =  'e' 


a =

  5×1 cell array

    {'a'}
    {'b'}
    {'c'}
    {'d'}
    {'e'}


cell2mat(a)

ans =

  5×1 char array

    'a'
    'b'
    'c'
    'd'
    'e'
Sign up to request clarification or add additional context in comments.

3 Comments

Oh actually I tried that one, I'll update my post
then you did get a 5x1 array of chars... what is the problem?
from your edit you have already a char array (in the original question you started from a cell array) , is what you want is just some different way that this info is visualized? because that's how char type letters are presented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.