【发布时间】:2016-12-01 08:03:16
【问题描述】:
我在执行多个循环时遇到了上述错误。我真的不知道如何解释这个问题,但我会尽力而为
代码:
function this = tempaddfilt(this,varargin)
fc = linspace(1,200,(200/0.5));
main = struct('seg_err',{},'sig_err',{},'filt_err',{},'fc',{});
for a = 1:length(fc) % fc
q = 0;
w = 0
for i = 1:length(this.segments) % total number signal
for k = 1:length(this.segments{i}) % total number of segments
filt_sig = eval(this.segments{i}(k).signal,this.segments{i}(k).signal(1)); % apply filter to the ith singal and kth segemnt
filt_sig = filt_sig';
main{i}(k).seg_err(a) = std(filt_sig-this.segments{i}(k).ref); % calculate the standard divitation of the filtered signal and previously calculated signal.
q = q+main{i}(k).seg_err(a); add all the error of the segments for the same FC
end
main{i}(1).sig_err(a) = q; % assign the sum of all error of the all segemnts of the same signal
w = w+main{i}(1).sig_err(a); % add all the error of the signals
end
main.filt_err = w; % assign the sum of all error of the all signals
end
this.error_norm = [this.error_norm ;main];
end
end
基本上我有 3 个循环,第一个循环用于 fc,第二个循环用于信号,第三个循环用于信号的段。当 fc = 1 时程序运行良好。
但是当 fc 为 2 时,我得到以下错误:
Cell contents assignment to a non-cell array object.
在行中:
main{i}(k).seg_err(a) = std(filt_sig-this.segments{i}(k).ref);
那是i =1,k=1,a = 2
【问题讨论】:
-
错误是说你试图将单元格的内容分配到一个数组中,比如 A = Cell(1,:) ;你可以试试
std(cell2double(filt_sig-this.segments{i}(k).ref))看看会发生什么。 -
@GameOfThrows,我没有找到任何叫 cell2double 的东西。
-
@CaptainFuture,我进行了调试,我在该行停止了程序并计算了命令窗口上的值。在这两个实例上,它都会返回一个值。
-
我没有在代码中实现它,而是再次停止了程序并在命令窗口@fc中检查了'iscell(std(filt_sig-this.segments{i}(k).ref))' = 1,fc = 2,都返回'0',我真的认为问题出在左侧。
-
@user5603723 是的,对不起,我的意思是 str2double - 在办公室度过漫长的一天。
标签: arrays matlab for-loop cell-array