problem in defining function in matlab

조회 수: 1 (최근 30일)
thanoon younis
thanoon younis 2015년 3월 1일
편집: per isakson 2015년 3월 1일
Hi everyone
I have a problem with the code below, in this code i want to write some equations. The problem with defining mu1 how can ii define it, i am new in matlab and i cannot define it.
for i=1:200
for j = 1:9
y{i,j}= CensoredGaussian(mu1(i,j),psi1(j),thd(j,z1(i,j)),thd(j,z1(i,j)+1));
end
mu1{i,1}= {mu.y1(1)+xi1(i,1)};
mu1{i,2}= {mu.y1(2)+lam1(1)*xi1(i,1)};
mu1{i,3}= {mu.y1(3)+lam1(2)*xi1(i,1)};
mu1{i,4}= {mu.y1(4)+lam1(3)*xi1(i,1)};
end
The error is ??? Undefined function or method 'mu1' for input arguments of type 'double'.
Any help would be highly appreciated. many thanks in advance
  댓글 수: 1
Aravind Singh
Aravind Singh 2015년 3월 1일
Add Following code at first line. This will construct a cell array..
mu1 = cell(10,10);
c = cell(m, n) or c = cell([m, n]) creates an m-by-n cell array of empty matrices. Arguments m and n must be scalars.
see help for more info

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

채택된 답변

per isakson
per isakson 2015년 3월 1일
편집: per isakson 2015년 3월 1일
Add
mu1 = cell( 200, 4 );
before the for-loops and read Preallocate Memory for a Cell Array
Next replace
mu1{i,1}= {mu.y1(1)+xi1(i,1)};
by
mu1(i,1)= {mu.y1(1)+xi1(i,1)};
etc. to do what I believe you intended. And read Access Data in a Cell Array
Finally, I would like to ask, why do you use cell arrays in the first place.

추가 답변 (1개)

thanoon younis
thanoon younis 2015년 3월 1일
편집: per isakson 2015년 3월 1일
Thank you very much for your response. I have now a problem here
for j = 1:9
y1{i,j}= CensoredGaussian(mu1(i,j),psi1(j),thd(j,z1(i,j)),thd(j,z1(i,j)+1));
end
the problem is
??? Error using ==> subsindex
Function 'subsindex' is not defined for values of class 'cell'.
how can i define subsindex using cell
many thanks again
  댓글 수: 1
per isakson
per isakson 2015년 3월 1일
편집: per isakson 2015년 3월 1일
  • Did you preallocate y1?
  • What does CensoredGaussian return?

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

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by