Writing a function in MATLAB was clear enough, but I ran into a little issue I want to correct. When I wrote functions in the past, I was doing them to test a program. The newest function I wrote actually computes something within a program - and it works. The issue I have is calling the function.
With a built-in MATLAB function, say isnan, in the command prompt I can write
M = isnan(A)
for some array A. Then immediately M will be the result of the operation isnan(A).
When I wrote a function, let us call it modify. When I try
M = modify(A)
in the command prompt, I am given the following error
Error using modify
Too many output arguments.
I don't do anything at the end of my function. It ends with a loop. How can I modify my function so that I can assign to it any variable name? I want to be able to perform the same variable assignment on my function as 'M = isnan(A)' above.

 채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 10일

2 개 추천

I have tried with similar, I have no issue
i1.png
If I misundestood the question, please clarify?

댓글 수: 3

John D'Errico
John D'Errico 2019년 6월 10일
The important point being that as has been done here, in the function header, you see the variable M being returned as written by Kalyan. So M is created inside the function.
Now, when you use it use it like this:
Y = modify(A);
You can stuff the result into any variable.
BM
BM 2019년 6월 10일
편집: BM 2019년 6월 10일
Hi Kalyan,
Yes, this works. My mistake was that I defined my function as
function modify(A)
rather than
function G = modify(A)
This solves the issue completely!
Out of everything to make a mistake on, I do it only on the simplest part!
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 10일
@John Thanks

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

BM
2019년 6월 10일

댓글:

2019년 6월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by