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

2 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by