Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 将单元阵列转换为单个阵列_Mysql_Sql_Matlab - Fatal编程技术网

Mysql 将单元阵列转换为单个阵列

Mysql 将单元阵列转换为单个阵列,mysql,sql,matlab,Mysql,Sql,Matlab,从Matlab和mySQL开始,作为我查询的结果,我得到了以下类型的数组: my_result = 5×1 cell array {'a'} {'b'} {'c'} {'d'} {'e'} 我想得到这样一个简单的数组: [a, b, c, d, e] 这是我的密码: mysql( 'open', 'my_database', 'usr','passw' ) query = fileread('query1.sql');

从Matlab和mySQL开始,作为我查询的结果,我得到了以下类型的数组:

my_result =

  5×1 cell array

    {'a'}
    {'b'}
    {'c'}
    {'d'}
    {'e'}
我想得到这样一个简单的数组:

[a, b, c, d, e]
这是我的密码:

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

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

my_result = mysql(query);
我试图得到一个简单的数组:

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});
 

有没有一种方法可以首先获得正确的格式,或者轻松地将其正确转换?谢谢

只需使用cell2mat内置功能

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'

只需使用cell2mat内置功能

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'

MySQL不支持数组,所以你的问题很不清楚。MySQL不支持数组,所以你的问题很不清楚。哦,实际上我试过了,我会更新我的帖子,然后你得到了一个5x1字符数组。。。问题是什么?从您的编辑中,您已经有了一个字符数组(在最初的问题中,您是从一个单元格数组开始的),您想要的只是以不同的方式显示此信息吗?因为这就是字符类型字母的表示方式。哦,实际上我试过那个,我会更新我的帖子,然后你得到了一个5x1字符数组。。。问题是什么?从您的编辑中,您已经有了一个字符数组(在最初的问题中,您是从一个单元格数组开始的),您想要的只是以不同的方式显示此信息吗?因为这就是字符型字母的表示方式。