database - 将矩阵导出到 Microsoft Access。使用数据库/插入时出错
问题描述
你好! 以下是以下任务的代码:
- 使用单元格“A”的矩阵获得维度为 3*2 的矩阵“Q”;
- 然后矩阵“Q”以相同的维度(3 行,2 列)导出到 Microsoft Access。
(!)困难在于只有矩阵的第一行被写入 Microsoft Access(三个可用的),然后显示错误消息:
使用数据库/插入时出错(第 213 行)一般错误
test_matlab 中的错误(第 22 行)插入(conn,'Rtu',colnames,Q);
(?)请告诉我,为了在 Microsoft Access 中记录矩阵的所有三行,有必要添加/更正代码吗?
Q=[];
A={1, [3 5 8]} % array of cells
for j=1:2 % matrix column index
for i=1:3 % matrix row index
if j==1
Q(i,j)=A{1,j};
else
Q(i,j)=A{1,j}(1,i);
end
end
end
Q
conn = database('QWERT', '', '');
colnames = {'u1', 'u2'};
insert(conn, 'Rtu', colnames, Q);
close(conn);
- 我使用 matlab 版本 R2014b。
解决方案
我不使用 matlab,但正常的编程实践会建议将插入插入到您的外部 for 循环中:这可行吗?
Q=[];
A={1, [3 5 8]} % array of cells
conn = database('QWERT', '', '');
colnames = {'u1', 'u2'};
for j=1:2 % matrix column index
for i=1:3 % matrix row index
if j==1
Q(i,j)=A{1,j};
else
Q(i,j)=A{1,j}(1,i);
end
end
insert(conn, 'Rtu', colnames, Q);
end
Q
close(conn);
或者在插入周围放置另一个 for 循环...
推荐阅读
- c - 连续使用 2 个 fscanf
- google-compute-engine - 形状不能沿维度 0 分片 8 次
- spring - Spring Security 从正在显示的模板文件夹中阻止我的静态 html 页面
- python - 用pyproj映射经纬度坐标
- python - Tkinter:winfo_reqwith() 返回错误值
- node.js - 为什么使用适用于 JavaScript 的 AWS 开发工具包列出 S3 存储桶文件夹中的对象会返回空的 Contents 数组但 KeyCount 大于 1?
- aws-glue - AWS Glue 自定义分类器
- visual-studio - 在 Visual Studio 2019 中重新打开关闭的选项卡(撤消关闭)?
- flutter - 滚动未来的 ListView
- flutter - 未处理的异常:RangeError(索引):无效值:有效值范围为空:0