[未答复] 无法执行赋值,左侧索引与右侧大小不兼容

[复制链接]
lianghr 发表于 2021-1-13 16:34:32
本帖最后由 lianghr 于 2021-1-13 16:37 编辑

主程序中涉及到了RSQ代码:
  1. % --- Executes on button press in electrodeCalibrate.
  2. function electrodeCalibrate_Callback(hObject, eventdata, handles)
  3. % hObject    handle to electrodeCalibrate (see GCBO)
  4. % eventdata  reserved - to be defined in a future version of MATLAB
  5. % handles    structure with handles and user data (see GUIDATA)
  6. global pHmeter slope intercept Rsq efficeny

  7. [slope, intercept, Rsq, efficeny] = calibration(pHmeter);
  8. set(handles.slopeWindow,'String',num2str(slope));
  9. set(handles.interceptWindow,'String',num2str(intercept));
  10. set(handles.efficencyWindow,'String',num2str(efficeny));

  11. %%save calibration and to file
  12. calibdata{1}=num2str(slope);
  13. calibdata{2}=num2str(intercept);
  14. calibdata{3}=num2str(efficeny);

  15. save('electrodeCalibData.mat','calibdata');
复制代码
其中RSQ.m的具体代码如下:
  1. function [slope, intercept,xModel, yModel,Rsq] = RSQ(x,y)

  2. if size(x,2)>size(x,1)

  3.     x=x';

  4. end

  5. if size(y,2)>size(y,1)

  6.     y=y';

  7. end

  8. workMatrix=zeros(size(x));

  9. workMatrix(:,1)=x;

  10. workMatrix(:,2)=y;



  11. %remove NaNs

  12. workMatrix = workMatrix(all(~isnan(workMatrix),2),:);

  13. %remove infs

  14. workMatrix = workMatrix(all(~isinf(workMatrix),2),:);



  15. % calculate slope and intercept

  16. fitParam=polyfit(workMatrix(:,1),workMatrix(:,2),1);

  17. %calculate model x and y



  18. slope=fitParam(1);

  19. intercept=fitParam(2);

  20. yModel=workMatrix(:,1)*fitParam(1)+fitParam(2);

  21. xModel = workMatrix(:,1);



  22. workMatrix(:,3)=yModel;



  23. %calculate SSE,SSR,SST

  24. workMatrix(:,4)=workMatrix(:,2)-workMatrix(:,3); %SSE

  25. workMatrix(:,5)=workMatrix(:,2)-mean(workMatrix(:,2)); %SSR

  26. workMatrix(:,6)=workMatrix(:,3)-mean(workMatrix(:,2));%SST



  27. SSE=sum(workMatrix(:,4).^2);

  28. SSR=sum(workMatrix(:,5).^2);

  29. SST=sum(workMatrix(:,6).^2);



  30. Rsq=1-SSE/SST;
复制代码
但是运行后,就卡住了,然后过一段时间以后就开始报错:
  1. >> Test
  2. Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

  3. Error in RSQ (line 17)
  4. workMatrix(:,1)=x;

  5. Error in granCalc (line 12)
  6. [slope, intercept,xModel, yModel,rsquare] = RSQ(volumes,ygran);

  7. Error in Test>StartAutoTitration_Callback (line 937)
  8. [TA, gamma, rsquare]=granCalc(sampleSize, Cacid, titrationLog(1:titrationStep-1,1)./1000000, titrationLog(1:titrationStep-1,3));

  9. Error in gui_mainfcn (line 95)
  10.         feval(varargin{:});

  11. Error in Test (line 42)
  12.     gui_mainfcn(gui_State, varargin{:});

  13. Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Test('StartAutoTitration_Callback',hObject,eventdata,guidata(hObject))

  14. Error using Test>emfRead_Callback (line 359)
  15. Error while evaluating UIControl Callback.
复制代码
请教各位大神,这是什么原因出的错啊?是不是就与RSQ文件中的错误有关啊?应该怎么办啊?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

相关帖子
热门教程
站长推荐
快速回复 返回顶部 返回列表