필터 지우기
필터 지우기

Get value from function to be used in another program part 2

조회 수: 2 (최근 30일)
monkey_matlab
monkey_matlab 2016년 10월 19일
답변: Mauricio Bassallo 2021년 5월 3일
Hello,
I have this function
function [x y] = centroid(X)
X = X/sum(X(:));
[m,n]=size(X);
[I,J]=ndgrid(1:m,1:n);
centro = [dot(I(:),X(:)), dot(J(:),X(:))];
end
when I try to use this function call in another program to use the centro values, I get an error , "Output argument "x" (and maybe others) not assigned during call to "centroid"."
How can I use the data out from this function?
Here is my use case in another program:
A = centroid(X);
A(1,:)
Thanks.

채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 19일
MATLAB is case sensitive. You assign to X but your output argument is x (lower-case)
  댓글 수: 2
monkey_matlab
monkey_matlab 2016년 10월 19일
Hello Walter, THANKS for your input! If just type
centroid(X)
In my other program, I get the x,y values to show up in the command window. However, if I try to use the commands like that given above in another program:
A = centroid(X);
A(1,:)
I get the error and cannot access the x,y values.
Walter Roberson
Walter Roberson 2016년 10월 19일
You never assign to x or y . You assign to X (a different variable), and to I, J, m, n and centro . Any variable that appears on the left side if the "=" of your "function" line must usually be assigned to.

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

추가 답변 (1개)

Mauricio Bassallo
Mauricio Bassallo 2021년 5월 3일
Hi,
I have a model created in Simulink (also with Simscape elements) and I want that some some outputs (ports) of the model be sent to another program, which is going to return inputs to the model (control the model) based on the outputs that was sent by the model.
Does anyone have some idea about how to create an interface between Simulink model and a program in order to generate such dynamic?
Thnaks in advance for your reply!
Mauricio

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by