mysql - 将元胞数组转换为单个数组
问题描述
开始使用 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'
推荐阅读
- php - 如何计算一系列时间间隔的分钟差
- node.js - 这个 javascript 正则表达式 string.replace 有什么问题?
- flutter - 什么时候应该使用样式:TextStyle() 和 Theme.of()
- javascript - 我是否使用 ajax 正确调用了 Gitlab API?
- neo4j - Neo4j - 使用包含点的标题加载 CSV?
- java - 将 CompletableFuture 值从 IntStream 添加到最终的 CompletableFuture 变量
- mysql - 拖放列表,从mysql中的元素中保存顺序的最佳性能
- python - 在 Python 中仅打印列表中的奇数值
- node.js - ASK 游戏中的意图链接
- azure-iot-sdk - 错误:“安全包中没有可用的凭据”与 DPS SDK