I am getting error "Index in position 2 exceeds array bounds (must not exceed 6)"

2 ビュー (過去 30 日間)
SAKSHAM SHRIVASTAVA
SAKSHAM SHRIVASTAVA 2023 年 7 月 2 日
コメント済み: Torsten 2023 年 7 月 2 日
function [u,s,v,x,sigma]=pcarep(xi,nf)
% function [u,s,v,x,sigma]=pcarep(xi,nf)
% PCA reproduction of the original data matrix x dor nf components
% u,s,v and x as in svd matlab function [u,s,v]=svd(x)
% xi is the original input data matrix (with noise)
% x is the pca reproduced data matrix (filtered no noise)
% nf is the number of components to be included in the reproduction
t0=cputime;
[u,s,v]=svd(xi,0);
u=u(:,1:nf);
s=s(1:nf,1:nf);
v=v(:,1:nf);
x=u*s*v';
res=xi-x;
sst1=sum(sum(res.*res));
sst2=sum(sum(xi.*xi));
sigma=(sqrt(sst1/sst2))*100;
disp(['PCA CPU time: ',num2str(cputime-t0)]);
disp(['Number of conmponents: ',num2str(nf)]);
disp(['percent of lack of fit (PCA lof): ',num2str(sigma)]);
The above code is for Principal component analysis. I am running this code for my matrix named "HPLC_D4" which I am attaching here. But I m getting an error:
Index in position 2 exceeds array bounds (must not exceed 6).
Error in pcarep (line 12)
u=u(:,1:nf);
can anyone help me to get out of this problem?

回答 (1 件)

Torsten
Torsten 2023 年 7 月 2 日
You should try
[u,s,v]=svd(xi);
instead of
[u,s,v]=svd(xi,0);
  2 件のコメント
SAKSHAM SHRIVASTAVA
SAKSHAM SHRIVASTAVA 2023 年 7 月 2 日
still error is coming
"Index in position 2 exceeds array bounds (must not exceed 6).
Error in pcarep (line 13)
s=s(1:nf,1:nf);''
Torsten
Torsten 2023 年 7 月 2 日
Check the sizes:
[u,s,v]=svd(xi);
size(xi)
size(u)
size(s)
size(v)
What values are displayed ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by