Retun matrix from a function

I want to write a program which will return a matrix as output. there will be two inputs to the function. Inside the function a matrix 'v' is created (3*3) as shown in the below program. I need to extract the columns of matrix 'v' which contains non-negative numbers. for that I have used 'any' function and the required matrix 'u' is obtained. But the problem is Its giving error when this is executed. But when its run in command window I am able to see the matrix.... Is it possible to get the output using "varargou" in the function?
Pls help me.
The program used in matlab function block is given below.
function u = switching(g,h)
v=[0 0-g 0-g-h;1 1-g 1-g-h;2 2-g 2-g-h]';
t= any((v)<0);
u=v(:,~t);
end

댓글 수: 3

Simon
Simon 2013년 10월 25일
Hi!
What is the error message?
Do you want columns with only positive numbers or with at least one positive number?
Pinkymol
Pinkymol 2013년 11월 18일
Hi, The error is "MATLAB Function Interface Error: Data 'u' (#101) is inferred as a variable size matrix, while its specified type is something else." I want the columns with only positive numbers
If you want columns with only positive numbers, then what is the point of including the row
0 0-g 0-g-h
that is then transformed into a column? The 0 is never going to be positive.
Is there anything known about the range of g and h? It appears they can be negative, but can they ever be 0 or positive?

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

답변 (1개)

Walter Roberson
Walter Roberson 2013년 11월 18일

0 개 추천

varargout will not help for this situation.
At the beginning of the function, give
u = zeros(3, 3);
You are then allowed to give it a different (smaller) shape later.

카테고리

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

질문:

2013년 10월 25일

댓글:

2013년 11월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by