필터 지우기
필터 지우기

Why my function do not work and gives me an error message?

조회 수: 1 (최근 30일)
AN NING
AN NING 2018년 1월 29일
댓글: AN NING 2018년 1월 29일
function [y] = SEM(x)
% Find out the each column of standard error for a matrix
% x should be a nxm matrix or 1xm
y = nanstd(x)./sqrt(length(x) - sum(isnan(x)));
disp(y);
end
Command window:
>> x=weightm;
>> y=SEM(x)
Subscript indices must either be real positive integers or logicals. Error message: Subscript indices must either be real positive integers or logicals.
  댓글 수: 1
Morteza Hajitabar Firuzjaei
Morteza Hajitabar Firuzjaei 2018년 1월 29일
Dear friend,
you used indices, you should make sure you are using integers as indices or make sure you are using vectors or matrices
best wishes
Morteza Hajitabar Firuzjaei

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2018년 1월 29일
Most likely, you have a variable called SEM in your workspace which shadow your SEM function. Hence you're indexing that variable instead of calling the function. Get rid of that variable or rename it.
Note that your sem function will give incorrect results for matrices that have more columns than rows because of the use of length. I would strongly recommend replacing length(x) by size(x, 1) but that is irrelevant for your error.
  댓글 수: 1
AN NING
AN NING 2018년 1월 29일
Thank you, you are right, I changed the SEM into SEMM and the problem is solved.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Morteza Hajitabar Firuzjaei
Morteza Hajitabar Firuzjaei 2018년 1월 29일
Dear friend,
you used indices, you should make sure you are using integers as indices or make sure you are using vectors or matrices
best wishes
Morteza Hajitabar Firuzjaei

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by