Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.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/9/loops/2.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
计算(求和)循环内的误差-MATLAB_Matlab_Loops_For Loop - Fatal编程技术网

计算(求和)循环内的误差-MATLAB

计算(求和)循环内的误差-MATLAB,matlab,loops,for-loop,Matlab,Loops,For Loop,我正在比较两个函数,一个是解析解(直接从教科书中获得),另一个是使用我收集的实验数据 我需要计算两者之间的误差。我的做法如下: voltage_experimental_offset = xlsread('R21_C19_L21.xlsx','H118:H259'); trigger_experimental = xlsread('R21_C19_L21.xlsx','D118:D259'); t_experimental = xlsread('R21_C19_L21.xlsx','G11

我正在比较两个函数,一个是解析解(直接从教科书中获得),另一个是使用我收集的实验数据

我需要计算两者之间的误差。我的做法如下:

 voltage_experimental_offset = xlsread('R21_C19_L21.xlsx','H118:H259'); 
trigger_experimental = xlsread('R21_C19_L21.xlsx','D118:D259'); 
t_experimental = xlsread('R21_C19_L21.xlsx','G118:G259'); 

ii = length(voltage_experimental_offset);   
total = 0;

for i = 1:ii
error = (voltage_experimental_offset(i) - V_C(i)').^2;  % compute error
total = sum(error(:))                                   % sum error

end
问题是“总计”每次只显示“错误”我想为每次迭代添加错误


非常感谢您的帮助

您需要索引错误

error = zeros(size(voltage_experimental_offset));
for i = 1:ii
error(i) = (voltage_experimental_offset(i) - V_C(i)').^2;  % compute error
total = sum(error(:))                                   % sum error

end

@用户1412994:不要感谢回答者,投票表决并接受答案。