How do I create this in MATLAB?
formula.png

댓글 수: 2

James Tursa
James Tursa 2019년 8월 22일
What have you done so far? What specific problems are you having with your code? Do you know how to write a for-loop, or use the sum( ) function, or use the diff( ) function, or use the .* operator?
John Allen
John Allen 2019년 8월 22일
Yes, I know all of those, just never did it like this, so totally confused how to structure this one.

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

 채택된 답변

James Tursa
James Tursa 2019년 8월 23일
편집: James Tursa 2019년 8월 23일

0 개 추천

Take the denominator for instance. Literally written out, this would be
denominator = 0;
for k=1:K
denominator = denominator + B(k,j)^2;
end
Or, assuming the first dimension of B is K, then you could use the sum( ) function:
denominator = sum(B(:,j).^2);
You can construct similar code for the numerator.
Probably best if you code everything up using for-loops just to get something running that works. Then you can simplify things with the sum( ) and diff( ) functions. It is possible to do the entire operation to construct ds without loops.

댓글 수: 4

John Allen
John Allen 2019년 8월 23일
In my application, it is NMF based operation, so the matrix is K x T and I have J components, let's say 20 of them, and then after I apply NMF, I will get B = K x J and G = J x T.
This summation happens after I get B. So, wouldn't I need a nested 2d loop to go over both K and J ?
I understand your code, but I am trying to understand this in my head.
James Tursa
James Tursa 2019년 8월 23일
편집: James Tursa 2019년 8월 23일
"So, wouldn't I need a nested 2d loop to go over both K and J ?"
Yes. The code I had written above was only for the denominator part of the j'th element of ds.
I would still suggest you write out the looping code first to get some correct code running. Then you can worry about simplifying it using sum( ) and diff( ) etc.
John Allen
John Allen 2019년 8월 23일
OK, thank you very much, I think I get it now, I marked answer as accepted.
Thanks again! :)
James Tursa
James Tursa 2019년 8월 23일
If you have trouble, don't hesitate to post your current code and the problems you are having and we can still help you.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2019년 8월 22일

댓글:

2019년 8월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by