【发布时间】:2023-04-03 18:45:01
【问题描述】:
我在访问元胞数组中的表中的列时遇到问题。 我有一个看起来像这样的 matlab 函数:
function [tables, rthTables, iGateTables, lastValueTables] = dataEinlesen(~, tcoFiles)
tables = cell(4,4);
...
for ch
for pos = folder.channelData(ch + 1).mPlexPos
ch_pos = [ch + 1, pos + 1];
tableCyclceCorrOffset_n = allTableCycleCorrOffset{ch_pos};
test1 = tables{ch_pos};
test1 = test1.cycle_no;
test1 = tables{ch_pos}.cycle_no;
%tables{ch_pos}.cycle_no(end - (tableCyclceCorrOffset_n(end)):end) = tables{ch_pos}.cycle_no(end - (tableCyclceCorrOffset_n(end)):end) + cycleCorrections(1, ch + 1);
end
end
...
test1 行仅用于调试,我想要工作的是行:
tables{ch_pos}.cycle_no(end - (tableCyclceCorrOffset_n(end)):end) = tables{ch_pos}.cycle_no(end - (tableCyclceCorrOffset_n(end)):end) + cycleCorrections(1, ch + 1);
排队
test1 = tables{ch_pos}.cycle_no;
我收到错误:中间大括号 {} 索引生成了一个逗号分隔的列表,其中包含 2 个值,但它必须生成一个值才能 执行后续的索引操作。
在那之前的两行工作得很好:
test1 = tables{ch_pos};
test1 = test1.cycle_no;
得到我想要的结果。
由于该函数返回了我尝试访问的元胞数组,我还尝试使用控制台中的输出进行操作,效果也不错:
tablesO = dataEinlesen(tcoFile)
test1 = tablesO{1,1}.cycle_no
那为什么不
test1 = tables{ch_pos}.cycle_no;
在函数内部工作?我错过了什么?
编辑:
此时的表格是 {2501x18 表格,[],[],[]; 2501x18 表格,[],[],[]; 2501x18 表格,[],[],[]; 2501x18 表格,[], [], []} 单元格,因此 {1,1}、{2,1}、{3,1} 和 {4,1} 处的 2501x18 表格
test1 = tables{ch_pos}
返回一个 2501x18 的表格和
test1 = test1.cycle_no
将 test1 变为 2501x1 的两倍
同样如前所述,该函数将表作为输出返回,当我在控制台中对输出执行相同的 òne-line 操作时:
test1 = tables{1,1}.cycle_no
有效,直接返回 2501x1 双精度
编辑2:
一个完整且最小的例子:
function tables = testTables()
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
tableData = zeros(2501,18);
tableData(:,1) = 0:2500;
tablesVariablesNames = {'cycle_no', 'V_on', 'V_hot', 'V_cold', 't_max', 't_min', 't_delta', 't_p', 't_coolant', 't_c_max', 't_baseplate', 'i_cycle', 'delta_v', 'delta_t_c', 'on_time', 'off_time', 'Duty', 'timestamp'};
tables = cell(4,4);
table_X = array2table(tableData, 'VariableNames', tablesVariablesNames);
for i=1:4
tables{i,1} = table_X;
end
test1 = tables{1,1};
test1 = test1.cycle_no;
test1 = tables{1,1}.cycle_no;
end
有问题的列与我的其他函数中的列完全相同。为简单起见,所有其他列都只是 0。奇怪的是,在这个例子中它工作得很好。
编辑3:
我发现了问题,很快就会在这里发布答案。
【问题讨论】:
标签: matlab cell-array