本帖最后由 lianghr 于 2021-1-13 16:37 编辑
主程序中涉及到了RSQ代码:- % --- Executes on button press in electrodeCalibrate.
- function electrodeCalibrate_Callback(hObject, eventdata, handles)
- % hObject handle to electrodeCalibrate (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global pHmeter slope intercept Rsq efficeny
- [slope, intercept, Rsq, efficeny] = calibration(pHmeter);
- set(handles.slopeWindow,'String',num2str(slope));
- set(handles.interceptWindow,'String',num2str(intercept));
- set(handles.efficencyWindow,'String',num2str(efficeny));
- %%save calibration and to file
- calibdata{1}=num2str(slope);
- calibdata{2}=num2str(intercept);
- calibdata{3}=num2str(efficeny);
- save('electrodeCalibData.mat','calibdata');
复制代码 其中RSQ.m的具体代码如下:
- function [slope, intercept,xModel, yModel,Rsq] = RSQ(x,y)
- if size(x,2)>size(x,1)
- x=x';
- end
- if size(y,2)>size(y,1)
- y=y';
- end
- workMatrix=zeros(size(x));
- workMatrix(:,1)=x;
- workMatrix(:,2)=y;
- %remove NaNs
- workMatrix = workMatrix(all(~isnan(workMatrix),2),:);
- %remove infs
- workMatrix = workMatrix(all(~isinf(workMatrix),2),:);
- % calculate slope and intercept
- fitParam=polyfit(workMatrix(:,1),workMatrix(:,2),1);
- %calculate model x and y
- slope=fitParam(1);
- intercept=fitParam(2);
- yModel=workMatrix(:,1)*fitParam(1)+fitParam(2);
- xModel = workMatrix(:,1);
- workMatrix(:,3)=yModel;
- %calculate SSE,SSR,SST
- workMatrix(:,4)=workMatrix(:,2)-workMatrix(:,3); %SSE
- workMatrix(:,5)=workMatrix(:,2)-mean(workMatrix(:,2)); %SSR
- workMatrix(:,6)=workMatrix(:,3)-mean(workMatrix(:,2));%SST
- SSE=sum(workMatrix(:,4).^2);
- SSR=sum(workMatrix(:,5).^2);
- SST=sum(workMatrix(:,6).^2);
- Rsq=1-SSE/SST;
复制代码 但是运行后,就卡住了,然后过一段时间以后就开始报错:
- >> Test
- Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
- Error in RSQ (line 17)
- workMatrix(:,1)=x;
- Error in granCalc (line 12)
- [slope, intercept,xModel, yModel,rsquare] = RSQ(volumes,ygran);
- Error in Test>StartAutoTitration_Callback (line 937)
- [TA, gamma, rsquare]=granCalc(sampleSize, Cacid, titrationLog(1:titrationStep-1,1)./1000000, titrationLog(1:titrationStep-1,3));
- Error in gui_mainfcn (line 95)
- feval(varargin{:});
- Error in Test (line 42)
- gui_mainfcn(gui_State, varargin{:});
- Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Test('StartAutoTitration_Callback',hObject,eventdata,guidata(hObject))
-
- Error using Test>emfRead_Callback (line 359)
- Error while evaluating UIControl Callback.
复制代码 请教各位大神,这是什么原因出的错啊?是不是就与RSQ文件中的错误有关啊?应该怎么办啊?
|